Halving Sequence
A while loop divides an integer by two repeatedly until it is no longer greater than two.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static void main(String[] args) {
int x = 12;
while (x > 2) {
x = x / 2;
}
System.out.print(x);
}
}
A
0
B
1
C
2
D
3
Question Leaderboard
Not enough data yet to show leaderboard.
