Sample Tracing Problems Note: To check your answer place the code in a Java program and execute. 1. What is the result of the following loop? int x = 3; while (x < 15) { if (x > 10) System.out.print("|" + x); x++; } ___________________________________________________________________________ 2. How many X characters will be displayed by the following loop? int i = 0; while (i < 10) { if (i > 5 && i != 8) System.out.print( "X"); i++; } __________________________________________________________________________ 3. What will be the value of x after executing the following? int x; x = 10 + 23 / 10 * 19 % 5 - 10; __________________________________________________________________________ 4. What will be the complete output of the following program segment: for (int x = 2; x != 12; x = x + 2) System.out.print( x + "|" ); System.out.print("#" ); __________________________________________________________________________ 5. Use the following main method for the next two problems public static void main (String[] args) { int x = 1; int y = 5; while (y > x) { y = y + 2; x = x + x ; } System.out.println( " x = " + x + " y = " + y); } What would be the displayed value of x? What would be the displayed value of y? _________________________________________________________________________ 6. Use the following program for the next four questions. public class S { public static void main (String[] args) { int x = 2, y = 4; m1(x, y); System.out.println( "x = " + x + " y = " + y); } public static void m1(int a, int b) { a = a + 2 * b; b = a * b; System.out.println("a = " + a + " b = " + b); } } What would be the displayed value of a? What would be the displayed value of b? What would be the displayed value of x? What would be the displayed value of y? _________________________________________________________________________ 7. What will be the value of x after executing the following? int x = 0, a = 5, b = 5; if ( a > 0 ) if ( b < 0 ) x = x + 5; else if ( a > 5 ) x = x + 4; else x = x + 3; else x = x + 2; _________________________________________________________________________ 8. How many times will the value of x will printed out in the following loop? int x = 9; do { System.out.println(x); x --; } while (x >= 3);