Do while loop: Scanner keyboard = new Scanner(System.in); int max, n, c; max = -1; c =0; do { n = keyboard.nextInt(); if (n > max) { max = n; } c++;} while (c<10); System.out.print(max);
For loop: Scanner keyboard = new Scanner(System.in); int max, n, c; max = -1; c = 0; for (c=0; c<10; c++) { n = keyboard.nextInt(); if (n > max) { max = n; } } System.out.print(max);
2. Rewrite the following event control program to while loop and for loop. Scanner keyboard = new Scanner(System.in); int total = 0; int c = 1; int n = keyboard.nextInt(); while(c<2*n) { System.out.print(" "+c); total = total + c; c = c* 2; } System.out.println(total);
While loop: Scanner keyboard = new Scanner(System.in); int total, c, n; total = 0; c=1; n = keyboard.nextInt(); do { if (n >0) { System.out.print(" "+c); total = total + c; c = c* 2; } } while(c<2*n); System.out.print(total);
For loop: Scanner keyboard = new Scanner(System.in); int total, c, n; total = 0; n = keyboard.nextInt(); for (c=1; c<2*n; c = c* 2) { if (n >0) { System.out.print(" "+c); total = total + c; } } System.out.print(total);
3. Provide the value printed on the screenshot: public class While1 { public static void main(String [] args) { int x = 1; while(x < 10) { System.out.println("x = " + x); x++; }