gpt4 book ai didi

java - 代码不产生 java 输出

转载 作者:行者123 更新时间:2023-11-30 07:51:57 24 4
gpt4 key购买 nike

我正在尝试编写一个代码,计算每个月的 CD 值。假设您将10,000美元投入一张CD,年 yield 为6.15%。一个月后,CD 的值(value)为:

10000 + 10000 * 6,15/1200 = 10051.25

下个月之后:

10051.25 + 10051.25 * 6,15/1200 = 10102.76

现在我需要显示用户输入的特定月份数的所有结果,所以

第一个月=

第二个月=

但是我编写的这段代码没有打印任何内容。你能看出哪里出了问题吗?

提前致谢!

import java.util.Scanner;

public class CDValue {
public static void main(String[] args){
Scanner input = new Scanner(System.in);

System.out.println("Enter an amount");
double amount = input.nextInt();

System.out.println ("Enter the annual percentage yield");
double percentage = input.nextDouble();

System.out.println ("Enter the number of months");
int months = input.nextInt();

double worth = amount + amount * percentage / 1200;

for (int i = 1; i < months; i++) {

while (i != months) {
amount = worth;

worth = amount + amount * percentage / 1200;


}
System.out.print(worth);

最佳答案

您不能在

中修改 imonths
while (i != months) {
....
}

因此,如果满足 (i !=months) 条件,则循环将永远运行,并且您永远不会到达 System.out.print 语句。

关于java - 代码不产生 java 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33238354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com