Examples for Trace2.txt Construct the trace table and predict the output. ---------------------------------------------- // Example 1. public class Main { public static void main(String[] args) { int x = 5, y = 8; while(x + y < 100) { x = 2 * x + y; y *= 3; } System.out.println(x + " " + y + " " + (x + y)); } } ---------------------------------------------- // Example 2. // What is the output with the input 2? // with input 4; import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { int x = 5, y = 3, n; n = Integer.parseInt( JOptionPane.showInputDialog("Enter an int.")); while (x < 100 && y < 75) { x *= (n + 1); y *= (n - 1); System.out.print(x + " "); } } } ---------------------------------------------- // Example 3. // What is the output with the input "abc"? import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { int n = 2; String a; a = JOptionPane.showInputDialog("Enter a string"); while(a.length() <= 10) { a += (n + "#" + a.charAt(n - 1)); n += 2; } System.out.println(a); } } ---------------------------------------------- // Example 4. public class Main { public static void main(String[] args) { int x = 3, y = 5, z = 9; if ((x + y + z) % 3 == 1) System.out.println("Yes"); else System.out.println("No"); } } ---------------------------------------------- // Example 5. public class Main { public static void main(String[] args) { int x = 100, y = 74; while(x > 1 && y > 1) { if ((x + y) % 2 == 0) { x /= 2; y /= 3; } else { x /= 3; y /= 5; } System.out.print(x - y + " "); } } } ---------------------------------------------- // Example 6. // What does this program do? // Test with the inputs // racoon frog mouse dog wolf bear import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { String word; word = JOptionPane.showInputDialog"Enter a string"); while(word != "") { if (word.length() == 4) { System.out.println( "Output is ****."); } else { System.out.println( "Output is " + word + "."); } word = JOptionPane.showInputDialog"Enter a string"); } } } ---------------------------------------------- // Example 7. public class Main { public static void main(String[] args) { int x = 4, y = 17, i; for(i = x; i <= y + 2; i += 3) System.out.print(i + " "); System.out.println(); System.out.println(i); } } ---------------------------------------------- // Example 8. public class Main { public static void main(String[] args) { int i, j; j = 100; for(i = 73; i > 1; i /=3) j /= 2; System.out.println(j); } } ---------------------------------------------- // Example 9. // What does the following code do? import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { String word, c; char letter; int i, n = 0; word = JOptionPane.showInputDialog("Enter a string"); c = JOptionPane.showInputDialog("Enter a string"); letter = c.charAt(0); for(i = 0; i <= word.length() - 1; i++) if (word.charAt(i) == letter) n++; System.out.println(n); } } ----------------------------------------------