tg-me.com/topJavaQuizExplain/37
Last Update:
How many times will the following code print "Hello World"?
3: for(int i=0; i<10 ; ) {
4: i = i++;
5: System.out.println("Hello World");
6: }
❌ A. 9
❌ B. 10
❌ C. 11
❌ D. The code will not compile because of line 3.
❌ E. The code will not compile because of line 5.
✅ F. The code contains an infinite loop and does not terminate
Explanation:
In this example, the update statement of the for loop is missing, which is fine as the statement is optional, so option D is incorrect. The expression inside the loop increments i but then assigns i the old value. Therefore, i ends the loop with the same value In this example, the update statement of the for loop is missing, which is fine as the statement is optional, so option D is incorrect. The expression inside the loop increments i but then assigns i the old value. Therefore, i ends the loop with the same value.
BY Explanations “Top Java Quiz Questions”
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Share with your friend now:
tg-me.com/topJavaQuizExplain/37