# Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number.

## Presentation on theme: "Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number."— Presentation transcript:

Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number != 0);

Write code snippet to replace every 'a' in the String S8 with 'x' Note – we can’t replace an element in a String. So – how in the world can we do this?

Hand Trace and Output: int total = 25; for (int number = 1; number <=(total / 2); number++) { total = total + number; System.out.println(total + " " + number); }

Hand Trace and Output: for (int i = 1; i <=3; i++) System. out
Hand Trace and Output: for (int i = 1; i <=3; i++) System.out.println("How many lines"); System.out.println("are printed?");

Hand Trace and Output: Hint In your hand trace, include 10 - i and 2
Hand Trace and Output: Hint In your hand trace, include 10 - i and 2*i -1 as columns for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10 - i ; j++) System.out.print(" "); } for (int j = 1; j <= 2* i -1; j++) System.out.print("*"); System.out.println();

5. Hand Trace and Output int n1 = 1; while (n1 < 100) { System. out
5. Hand Trace and Output int n1 = 1; while (n1 < 100) { System.out.print(n1 + " "); n1 += 10; }

6. Hand Trace and Output int n1 = 100; while (n1 > 0) { System. out
6. Hand Trace and Output int n1 = 100; while (n1 > 0) { System.out.println(n1 / 10); n1 = n1 / 2; }

7. Given: // Pre: int // Post: nothing public static void mystery(int x) { int y = 1; int z = 0; while (2 * y <= x) y = y * 2; z++; } System.out.println(y + " " + z); What is Output: mystery(1) mystery(19)

8. Write method called randomX in systemMethods that prints a line that contains a random number of "x" characters (between 5 and 20 inclusive) until it prints a line that contains 16 or more characters. For example, the output might look like xxxxxxxx xxxxxxxxxxx xxxxxxx xxxxxx xxxxxxxxxxxxxxxxxx

9. Write a method checkLet that accepts a String and a char and returns true or false which is the answer to the question "Is the char in the String?".

Download ppt "Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number."

Similar presentations