// // CS-201 // // Lab 3 // // Tracing Loops // // For each loop manually determine the output displayed // then check your results by compiling and running // public class Loops { public static void main (String[] args) { int x, y; char c1, c2; System.out.println( "\n*** Loop 1 ***\n"); x = 2; while (x < 10) { System.out.println( "\nx = " + x); x = x + x; } System.out.println( "\nLoop 1 FINAL VALUE: x = " + x); System.out.println( "\n\n*** Loop 2 ***\n"); x = 2; y = 20; while (x < y) { System.out.println( "\nx = " + x + " y = " + y); x = x + 2; y = y - 3; } System.out.println( "\nLoop 2 FINAL VALUES: x = " + x + " y = " + y); System.out.println( "\n\n*** Loop 3 ***\n"); x = 2; y = 40; while (x + 2 < y - 5) { System.out.println( "\nx = " + x + " y = " + y); x = x + 2; y = y - 3; } System.out.println( "\nLoop 3 FINAL VALUES: x = " + x + " y = " + y); System.out.println( "\n\n*** Loop 4 ***\n"); x = 2; y = 40; while (x * 2 < y) { x = x + 4; y = y - 4; } System.out.println( "\nLoop 4 FINAL VALUES: x = " + x + " y = " + y); System.out.println( "\n\n*** Loop 5 ***\n"); c1 = 'a'; c2 = 'm'; while (c1 <= c2) { System.out.println( "\nc1 = " + c1 + " c2 = " + c2); c1 = (char)((int)c1 + 1); c2 = (char)((int)c2 - 1); } System.out.println( "\nLoop 5 FINAL VALUES: c1 = " + c1 + " c2 = " + c2); System.out.println("\nEND OF PROGRAM\n\n"); } }