为了账号安全,请及时绑定邮箱和手机立即绑定

可以看下我哪里写错了吗?(java)

可以看下我哪里写错了吗?(java)

慕移动2184654 2018-05-18 02:23:59
Scanner sc=new Scanner(System.in);   System.out.println("what is the number of organisms");   int ornumber=sc.nextInt();   System.out.println("what is the increase in their population size (as percentage) per unit time");   int pernumber=sc.nextInt();   System.out.println("what is the number of units of time he wants to see the population size ");   int timeunit=sc.nextInt();   int b=timeunit;   for (int a=1;a<=b;a++) {   int total=ornumber+(a*(ornumber*(pernumber/100)));   System.out.println(total);       }我打印出来的结果 都是相同的,这个不可能啊我想让a= 1 2 3 4 5......循环每行印出它代表的量但是结果竟然是a等于1和后面等于2 3 .....的结果都一样
查看完整描述

2 回答

?
伤心的夏天

TA贡献5条经验 获得超3个赞

(a*(ornumber*(pernumber/100)))这一堆的结果是int类型的,如果值小于1就直接等于0了,所以等式就变成了 int total=ornumber,所以每次结果都一样。

查看完整回答
反对 回复 2018-05-21
?
半枯

TA贡献101条经验 获得超45个赞

如果你的pernumber>=100,ornumber!=0是不会有这样的情况的

查看完整回答
反对 回复 2018-05-18
  • 2 回答
  • 0 关注
  • 955 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信