package chaper1;
import java.math.BigInteger;
public class MoodBan {
public static void main(String[] args) {
// TODO Auto-generated method stub
BigInteger balance= new BigInteger("10000");
double rate = 0.03;
int years = 0;
while ( balance>=12000) {
balance = balance+(balance*rate);
years++;
System.out.printf("%d年之后,账户本金:%f\n",years,balance);
}
System.out.println("存款"+years+"后,账户本金超过12000!!");
}
}
double balance = 10000;
double rate = 0.03;
int years = 0;
while (balance <= 12000) {
balance = balance + (balance * rate);
years++;
System.out.printf("%d年之后,账户本金:%f\n", years, balance);
}
System.out.println("存款" + years + "后,账户本金超过12000!!");
balance=10000,小于12000,进不了循环呀。
while ( balance>=12000) {
应该改为
while ( balance<=12000) {
balance 是10000
while 循环条件( balance>=12000)一开始就不成立,一次也不会循环
应该是 while ( balance<=12000) {吧, >= 改成 <=
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!