标签:class mat col switch des 语句 bre 循环结构 cas
int a = 18; if(a < 60){ return ‘D‘; }else if(a<70){ return ‘C‘; }else if(a<80){ return ‘B‘; }else{ return ‘A‘; }
int week = 2; switch (week){ case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wendesday"); break; default: System.out.println("sorry, i dont know"); }
int a = 0;
while (a < 0){
System.out.println(a);
a++;
}
System.out.println("-----------");
//while和do-while的区别是do-while会保证循环体至少被执行一次
a=0;
do{
System.out.println(a);
a++;
}while (a < 0);
//for循环
for (a = 0; a < 0; a++){
System.out.println(a);
a++;
}
//需求1:生成0-100随机数,直到生成88为止,停止循环 int total = 0; System.out.println("Begin!"); while (true){ total ++; int i = (int)Math.round(100 * Math.random()); if (i == 88) break; } System.out.println("Game over,used " + total + "times."); System.out.println("------------"); //需求2:输出100~150之间不能被3整除的数 for (int i = 100; i < 150; i++){ if (i % 3 == 0) continue; System.out.println(i); }
outer: for (int i = 101; i < 150; i++){ inner: for (int j = 2; j < i / 2; j++){ if (i % j == 0){ continue inner; } System.out.println(i + " " + j); }
标签:class mat col switch des 语句 bre 循环结构 cas
原文地址:https://www.cnblogs.com/Emking/p/12147642.html