Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
hard

Digit Extraction

Mark
< Prev
Next >

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

Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|