求一个计算银行本息问题的程序

来源:百度知道 编辑:UC知道 时间:2024/05/05 03:17:27
现有1000元钱 利率和年数自己从控制台输入 利率每年增加%3
最后的钱是多少?
要求要用while 循环写

import java.util.Scanner;

public class Xunhuan3 {

/**
* @param args
*/
private static double money = 1000;// 初始本金

private Scanner sc;

private String readString() {
sc = new Scanner(System.in);
return sc.next();
}

private int readInt() {
sc = new Scanner(System.in);
return sc.nextInt();
}

private double readDouble() {
sc = new Scanner(System.in);
return sc.nextDouble();
}

private void getMoney() {
try {
System.out.println("请输入年数(int 型)");
int year = this.readInt();
System.out.println("请输入利率(double 型)");
double lilv = this.readDouble();
int i = 0;
double newMoney = money;
while (true) {
if (i < year) {
newMoney = newMoney * (1 + lilv + 0.03 * i);
i++;
} else {
break;
}
// Str