1. Sequence Structure
int a = 18;
if(a < 60){
return 'D';
}else if(a<70){
return 'C';
}else if(a<80){
return 'B';
}else{
return 'A';
}
2. Select structure
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");
}
3. loop structure
A 0 = int;
the while (A <0) {
System.out.println (A);
A ++;
}
System.out.println ( "-----------");
// do the while and -while the difference will ensure the do-while loop is executed at least once
a = 0;
do {
System.out.println (a);
a ++;
} the while (a <0);
//for循环
for (a = 0; a < 0; a++){
System.out.println(a);
a++;
}
4. Jump
// Requirement 1: 0-100 generates a random number generated until 88, the circulation was stopped
int Total = 0 ;
System.out.println ( "the Begin!" );
The while ( to 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 ( "------------" );
// Requirement 2: output 100 to 150 can not be divisible 3
for ( int I = 100; I <150; I ++ ) {
if (i % 3 == 0)
continue;
System.out.println(i);
}
5. Multi-cycle
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);
}