我有一個方法返回到主要方法的問題。這就是說,「回報金額」中的金額不能解析爲變量。我在哪裏關閉?返回問題的方法
這是我得到的消息:在該行 多個標記 - 太虛方法不能返回 值 - 量不能被解析爲 可變
下面是代碼:
import java.util.Scanner;
public class Investment {
public static void main(String[]args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the amount invested: ");
double amount = input.nextDouble();
System.out.print("Enter the annual interest rate: ");
double interest = input.nextDouble();
int years = 30;
System.out.print(futureInvestmentValue(amount, interest, years)); //Enter output for table
}
public static double futureInvestmentValue(double amount, double interest, int years) {
double monthlyInterest = interest/1200;
double temp;
double count = 1;
while (count < years)
temp = amount * (Math.pow(1 + monthlyInterest,years *12));
amount = temp;
System.out.print((count + 1) + " " + temp);
}
{
return amount;
}
}
嘗試縮進代碼。使閱讀更容易。 –
你不能從main方法返回一些東西。刪除返回並打印一些消息或錯誤。 – sathis
請添加適當的標籤並縮進您的代碼。 – svinto