Digit Extraction
A program processes digits of an integer using modulo and division to calculate a specific sum.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static void main(String[] args) {
int n = 452;
int res = 0;
while (n > 0) {
res += n % 10;
n /= 100;
}
System.out.println(res);
}
}
A
4
B
11
C
6
D
9
Question Leaderboard
Not enough data yet to show leaderboard.
