首页 新闻 会员 周边

Java while 循环

0
悬赏园豆:20 [待解决问题]
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   }
问题补充:

要每一步详细解析

代码洁癖爱好者的主页 代码洁癖爱好者 | 初学一级 | 园豆:190
提问于:2015-10-29 20:11
< >
分享
所有回答(1)
1

等于6不是吗?

第一次进入while后:m = 5; result = 5; s = 10

第二次进入while后:m = 0; result = 5; s = 1

第三次进入while后:m = 1; result = 6; s = 0

不符合条件退出

苏幕遮soft | 园豆:401 (菜鸟二级) | 2015-10-29 21:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册