Java Programming Basics Review notes Unit IV

Source: Internet
Author: User

1 think before Codingcode incrementally2sentinel valuesentinel-controlled loop3 input/output redirection > <input redirectionoutput Redirection4pretest loopposttest loop5 Add floating-point numbers from small to large accurate 6integer.tobinarystring (int) integer.tohexstring (int) 7PIE =4 * (1-1/3 + 1/5-1/7 ...-1/(2 * i-1) + 1/(2 * i + 1)) Keywordbreak statementcontinue Statementdo-while Loop For Looploop control Statementinfinite loopinput redirectioniterationlabeled continue Statementlooploop-condition Condition: Loop control condition Loop bodynested bodyoff-by-one erroroutput redirectionsentinel valuewhile loop4.1 always true4.2 infinite loop 4.3 infinite times 9 times 9 times 111111111111111112,4,6,83,5,7,94.4 loop control conditions and loop body execution order int sum = 0;int Number = 0;do{sum + = number; Number = Input.nextint ();} while (number! = 0) 4.5 is the same as 4.6 loop initialization, loop control condition, after each iteration operation for (int i = 0;i < 100;i++) System.out.println (i+1); 4.7max are 5number is 0 4.8sum is 14number is 04.9max are 5number is 04.10 infinite loop 4.11 can not 4.12, but for loop more direct, clear 4.13long sum =0;int i = 0;while (i <= 100 0) {sum + = i++;} /*do{sum+=i++;} while (I&Lt;=1000) */4.14cant because of integer division4.15 jumps out of the current loop, jumps out of the current iteration, can, 1, cannot 4.16int sum = 0;int i = 1;for (; sum < 10000;i++) s Um + = i;4.17if (i% 3 = = 0) {i++;continue;} 4.18.........4.19system.out.println (i); 1;4.20system.out.println (i); 1;4.212 public static Void3:int I declare in the LOOP 5: Declare int J and Initialize 7: Semicolon 11: Remove the semicolon 4.22 uninitialized; add a semicolon; 4.230 0 1 0 1 2 3 0 1 2 3 4;compile error;1xxx2xxx4xxx8xxx16xxx1xxx2xxx4xxx8xxx1xxx2xxx4xx X1xxx2xxx1xxx;1g1g2g1g2g4g1g2g4g8g1g2g4g8g16g;4.24no output result;because The loop never end4.25nn-5n+1 (n-3)/ 3 Programming Questions 4.23//left-to-right double sum = 0;for (int i =1;i<=50000;i++) {sum + = 1d/i;} SYSTEM.OUT.PRINTLN (sum);//11.397003949278504//right-to-left double sum = 0;for (int i = 50000;i >= 1;i--) {sum + = 1d/i;} SYSTEM.OUT.PRINTLN (sum);//11.397003949278519

  

Java Programming Basics Review notes Unit IV

Related Article

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.