Compute digit sum of int n with:
<code>int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } </code></pre> For n = 234, sum is
- Acheck_circle
9
- B
12
- C
15
- D
6
Explanation
2 + 3 + 4 = 9.
AP Computer Science A· difficulty 4/5
Compute digit sum of int n with:
<code>int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } </code></pre> For n = 234, sum is
9
12
15
6
Explanation
2 + 3 + 4 = 9.
Want 10 more like this — adaptive to your weak spots?
What does this print? <codeString s = "abc"; for (int i = 0; i < s.length(); i++) System.out.print(s.charAt(i)); </code</pre…
chevron_right<codewhile (i < 10) { ... }</code can be refactored to a <codefor</code loop as…
chevron_rightWhat's printed for s = "abcd"? <codefor (int i = 0; i < s.length(); i += 2) System.out.print(s.charAt(i)); </code</pre…
chevron_right