gpt4 book ai didi

java - 在简单且稍微冗余的代码中找不到符号

转载 作者:行者123 更新时间:2023-11-30 03:31:11 25 4
gpt4 key购买 nike

当我编译此代码时,出现错误:在最后一段中找不到符号 > InvestmentAmount。如果我取出所述片段:

JOptionPane.showMessageDialog(null, "The total amount you have to pay after 5 years is " 
+ Math.pow(investmentAmount(interestRate+1),5));

那么其余的代码就可以工作,除了我需要那段代码才能通过。如果我在该部分取出investmentAmount,但保留interestRate,那么代码可以完美运行,并给出五年后的金额。为什么 InvestmentAmount 在代码的前面起作用,而不是在最后?为什么interestRate最后没有弄乱代码而investmentAmount却弄乱了?这是完整的代码-

import javax.swing.JOptionPane;

public class Ch3IndLabAssignment
{
public static void main( String [] args )
{
String investorName = JOptionPane.showInputDialog( null, "Please enter your first and last name");
JOptionPane.showMessageDialog(null, "Your name is " + investorName);

String input = JOptionPane.showInputDialog( null, "Please enter your investment amount");
double investmentAmount = Double.parseDouble(input);
JOptionPane.showMessageDialog(null, "Your investment amount is " + investmentAmount);

String input2 = JOptionPane.showInputDialog( null, "Please enter the interest rate as a decimal");
double interestRate = Double.parseDouble(input2);
JOptionPane.showMessageDialog(null, "Your interest rate is " + interestRate);

JOptionPane.showMessageDialog(null, "The total amount you have to pay back after 5 years is " +
Math.pow(investmentAmount(interestRate+1),5));
}
}

最佳答案

在代码中

JOptionPane.showMessageDialog(null, "The total amount you have to pay after 5 years is " 
+ Math.pow(investmentAmount(interestRate+1),5));

您将 InvestmentAmount 视为一种带有一个参数的方法,该参数为 interestRate+1。也许您的意思是:

JOptionPane.showMessageDialog(null, "The total amount you have to pay after 5 years is " 
+ Math.pow(investmentAmount*(interestRate+1),5));

注意*

关于java - 在简单且稍微冗余的代码中找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29000155/

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