Older Dick Silk Self-study note--java 0 basics to rookie--011

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.