Question 5
Back to Exercise
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
int a = 0, b = 0, c = 0;
for (int i = 0; i < 20; i += 3) a++;
for (int i = 20; i > 0; i /= 2) b++;
for (int i = 1; i <= 1000; i *= 10) c++;
System.out.println(a + " " + b + " " + c);
}
}
- A 7 5 4 Correct
- B 6 5 4
- C 7 4 3
- D 7 5 3
Correct Answer: Option A
0, 3, … 18 is 7 values; 20, 10, 5, 2, 1 is 5; 1, 10, 100, 1000 is 4.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!