175k views
2 votes
What will be the output of the following code snippet? boolean token1 = true; while (token1) { for (int i = 0; i < 10; i++) { System.out.println("Hello"); } token1 = false; }

1 Answer

5 votes

Answer:

The output of the code snippet will be ten “Hello” messages

Step-by-step explanation:

while token = true

i = 0 sends “Hello” to the screen

i = 1 sends “Hello” to the screen

i = 2 sends “Hello” to the screen

i = 3 sends “Hello” to the screen

i = 4 sends “Hello” to the screen

i = 5 sends “Hello” to the screen

i = 6 sends “Hello” to the screen

i = 7 sends “Hello” to the screen

i = 8 sends “Hello” to the screen

i = 9 sends “Hello” to the screen

User Ocram
by
5.4k points