Java: Fifth Chapter

Source: Internet
Author: User

The fifth chapter cycle structure
1.while Cycle
while (condition) {
code block
}
Explanation: If the result of the condition is true, then the code block is executed,
When a block of code finishes executing, the condition is executed,
Loop until the result is false and the entire loop ends.

2. Program debugging
First step: Set breakpoints (left-click)
The second step: Debug way to execute code.
Step three: Execute code-by-article Debugging (F6)
Fourth step: Check the code (see changes in variable values)
Note: The Java view and debug view can be toggled in the upper right corner.

3.do while loop
do{
code block
}while (condition)
Explanation: Execute the code block first and then make the conditional judgment
If the condition is true, continue to execute the code block
One loop until the condition is false, the entire loop
End.
Note: The scope of the variable
(from the beginning of the variable declaration to the end of its block of code)

4.while and Do...while differences
A. The order of execution is different
The loop body in the b.do...while is executed at least once,
While the loop body in the while has a false result,
will not be executed.

 Public class*** {     Public Static voidMain (string[] args) {inti =1;  while(i<= -) {System. out. println ("Section"+i+"take a good study and make progress every day"); I++; }    }} Public class***{     Public Static voidMain (string[] args) {Scanner console=NewScanner (System.inch); //condition number >1000000//Cyclic count = count* (1+0.25);        intnum =1 ; intCount =250000;  while(count<=1000000) {Count= (int) (Count* (1+0.25)); Num++; } System. out. println ( -+num); }    } Public class***{     Public Static voidMain (string[] args) {Scanner input=NewScanner (System.inch); System. out. println ("Please enter Celsius:"); DoubleXY =input.nextdouble (); intCount =0;  Do{            DoubleH = xy*9/5.0+ +; System. out. println (xy+"corresponding to Fahrenheit:"+h); XY= xy+ -; Count++; } while(count<Ten&&xy<= -); }}

Java: Fifth Chapter

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.