Digit Extraction Logic
Use integer division and modulus operators to isolate digits of an integer.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static void main(String[] args) {
int val = 876;
int a = val / 100;
int b = (val % 100) / 10;
int c = val % 10;
System.out.print(a + b + c);
}
}
A
21
B
876
C
8
D
15
Question Leaderboard
Not enough data yet to show leaderboard.
