1 point (e) n=1000; while (n>10) { n=n/10; } System.out.println(n); How many time the loop is executed and what is the output?
(options)
1) Loop is executed: 2 times and the output is 100
2) Loop is executed 2 times and the output is 10.
3) Loop is executed 3 times and the output is 10
Answers
Answered by
8
Answer:
2
Explanation:
1 st iteration 1000/10=100>10
condition satisfied so it goes to next iteration
in 2ndbiteratiin 100/10=10!>10
so loop terminates
output is 10
Answered by
3
"Option 2):Loop is executed 2 times and the output is 10".
Explanation :
In the first loop, while loop check 1000 is greater than 10 in condition. The Condition is true, So it enters the loop. Now 1000/10 which becomes 100.
In the second loop, Now the "n" value is 100 is greater than 10. The Condition is true, So it enters the loop. Now 100/10 which becomes 10.
Goes to the next loop, Now the "n" value is 10 is not greater than 10. So the condition fails. The loop ends.
At last, the "n" value is 10 and the loop is executed 2 times.
Similar questions