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≪=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