代码和计算是正确的,我只是不知道如何正确格式化它
static void main(String[] args) {
Scanner input = new Scanner(System.in);
String inputString;
char flag = 'c';
while(flag =='c' || flag == 'C') {
System.out.print("Enter your investment amount");
double futurevalue=input.nextInt ();
System.out.print("Enter the interest rate (%)");
double interest = input.nextInt ();
int i;
for (i =0; i<=5; i++)
futurevalue = futurevalue * (1 + (interest/100));
System.out.printf("Your value is" + futurevalue);
System.out.printf("Enter c to continue or any other key to quit: ");
input.nextLine();
inputString = input.nextLine();
flag = inputString.charAt(0);
}
}
}
期间1%
<小时/>1 505.00
2510.05
3515.15
4520.30
5525.51
这就是它需要的样子
最佳答案
我不确定您在寻找什么。如果您希望每个循环打印答案
for (int i = 0; i <= 5; i++) {
futurevalue = futurevalue * (1 + (interest / 100));
System.out.println((i+1) + " " + futurevalue);
}
关于java - 我必须打印出这个方程的 5 个 future 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36365785/