68.4k views
4 votes
What is the outcome of the following code snippet? boolean val1 = true; boolean val2 = false; while (val1) { if (val1) { System.out.println("Hello"); } val1 = val2; } No output will be displayed because of a compilation error. Hello will be displayed only once. Hello will be displayed infinite times. No output will be displayed even after successful compilation of the code snippet.

1 Answer

4 votes

Answer:

Hello will be displayed only once.

Step-by-step explanation:

Look at the picture*

What is the outcome of the following code snippet? boolean val1 = true; boolean val-example-1
User MikeBaker
by
8.0k points