1 //比较break和continue语句的不同 2 public class TestBreakContinue { 3 public static void main(String[] args){ 4 int a = 0; 5 System.out.println("Begin"); 6 while(true){ 7 a++; 8 int b = (int)Math.round(100*Math.random()); 9 if(b==88)break; 10 } 11 System.out.println("Game Over\n"+"you used "+ a +" times"); 12 System.out.println("**********************"); 13 for(int i = 100;i<=150;i++){ 14 if(i%3==0) 15 continue; 16 System.out.println(i); 17 } 18 //带标签的break和continue---goto 19 System.out.println("*******************"); 20 int count = 0; 21 //100~150之间有多少质数 22 outer:for(int n=101;n<150;n++){ 23 for(int m=2;m<n/2;m++){ 24 if(n%m==0) 25 continue outer; //直接返回第一个for循环;n的值不会被重置 26 } 27 System.out.print(n+"\t"); 28 count++; 29 } 30 System.out.println("总共有"+count+"个质数"); 31 32 33 } 34 35 }
原文地址:https://www.cnblogs.com/zbgghost/p/8428717.html
时间: 2024-10-07 01:47:07