public static void main(String[] args) { |
02 |
int s = 105; |
03 |
int result = 0; |
04 |
while (s > 0) { |
05 |
int m = s % 10; |
06 |
result += m; |
07 |
s /= 10; |
08 |
} |
09 |
System.out.println(result); |
10 |
} |
要每一步详细解析
等于6不是吗?
第一次进入while后:m = 5; result = 5; s = 10
第二次进入while后:m = 0; result = 5; s = 1
第三次进入while后:m = 1; result = 6; s = 0
不符合条件退出