Looping statements: For, while...do, Do...while
1. For: (Initialize statement; Judge conditional statement; Control condition statement) {loop body statement;}
1 classfin{2 Public Static voidMain (string[] args) {3 for(inti=0;i<10;i++){4System.out.println ("Hello World");5 }6 }7 }8 9 //I have an initial value of 0, less than 10, the output of the 1th "Hello World", and then Execute "i++", until i=10, not meet the "i<10" control conditions, the end of the cycle, a total of 10 "Hello World"
Narcissus number: Number of cubes and equal to its own three-digit number, such as: 153=1*1*1+5*5*5+3*3*3=153.
1 classfin{2 Public Static voidMain (string[] args) {3 for(inti=100;i<1000;i++){4 inta=x%10;//Digit5 intb= (X/10)%10;//10 Guests6 intc=x/100;//Hundred7 8 if((a*a*a+b*b*b+c*c*c) = =i) {9System.out.println (i);//number of daffodils outputTen } One } A } -}
2. While...do:while (Judgment condition statement) {loop body statement; Control condition statement;}
1 classfin{2 Public Static voidMain (string[] args) {3 intN=0;4 while(n<10){5System.out.println ("Hello World");6n++7 }8 }9 }Ten One //output of 10 "Hello World"
3. do...while:do{loop body statement; Control condition statement;} while (judging conditional statements)
1 classfin{2 Public Static voidMain (string[] args) {3 intN=0;4 Do{5System.out.println ("Hello World");6n++7} while(n<10)8 }9 }Ten One //output of 10 "Hello World"
Older Dick Silk Self-study note--java 0 basics to rookie--011