Playing Compiler
Find the errors in the following statements. If a statement has no errors, then say so. If a statement contains errors, correct them. In each case describe the action of the loop.
a. for (int i = 1; i < = 10; i++) { i = i − 1 }b. int j = 7; while (j > 1) { system.out.println (“again”); j = j % 2 }c. intj = 1; while (j = 1) { System.out.print(“try again”); }d. for (int k =1, k == 20; k+ +) {}e. for (float h = 0.0; h<5.0; h = h + .01) System.out.println(h);
f. for (double h = 0.0; h<5.0; h = h + .01) { System.out.println(h); }g. do { int k = 3; System.out.print(k); } while (k != 3);h. int k = 3; do { System.out.print(k); } while (k != 3);i. do { System.out.println("This looks correct") } while {true};j. while (true) { int x = x + 1; }k. int m = 2; while (m > 0) do { m = m − 1; }; l. int m = 2; while (m > 0) do { m = m − 1; System.out.println(m); };m. int m = 2; while (m > 0) { m = m − 1; System.out.println(m); } while (false);n. int k; for (k = 0; k = 1; k+ +) { System.out.print(k = 1); }o. int x = 7; do (System.out.println(x); x--) while {x<2};p. for (int k = 0; k<100; k = ++k) System.out.println(k)
q. for (int k = 0; k<100; k = ++k) System.out.println(k);
r. for (int k = 0; k<100; k = k+ +) System.out.println(k);
s. for (int k = 0; k<100; k = ++k) System.out.println(k++);
t. for (int k = 0; k<100; k = ++k) System.out.println(--k);
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.