嘿伙计们,我正在编写这个程序,除了利率导致这个错误之外,我一切正常,
MenuDrivenProgram.java:92: possible loss of precision
found : double
required: int
deposit = balanceCurrent + interest;
^
1 error
这是我的代码,
public static void InvestmentReport()
{
System.out.printf("*** Investment Report stub ***\n");
// This is where your Part A solution goes
System.out.printf("*************** InvestmentReport Menu ***************\n\n");
Scanner console=new Scanner(System.in);
int deposit, monthly, interestRate;
double interest, balanceCurrent;
System.out.println ("Enter your initial deposit amount in dollars\n");
deposit = console.nextInt();
System.out.println ("Enter the annual interest rate as a percentage (eg. 6.0)\n");
interest = console.nextDouble();
System.out.println ("Enter your monthly deposit amount in dollars\n");
monthly = console.nextInt();
System.out.println ("Savings growth over the next 6 months:\n");
System.out.println ("Balance after first month: $" + deposit);
deposit = deposit + monthly;
System.out.println ("Interest earned for this month: $" + interest);
interest = balanceCurrent * interestRate / 12 / 100;
deposit = balanceCurrent + interest;
System.out.println ("Balance after second month: $" + deposit);
deposit = deposit + monthly;
System.out.println ("Interest earned for this month:\n");
System.out.println ("Balance after third month: $" + deposit);
deposit = deposit + monthly;
System.out.println ("Interest earned for this month:\n");
System.out.println ("Balance after fourth month: $" + deposit);
deposit = deposit + monthly;
System.out.println ("Interest earned for this month:\n");
System.out.println ("Balance after fifth month: $" + deposit);
deposit = deposit + monthly;
System.out.println ("Interest earned for this month:\n");
System.out.println ("Balance after sixth month: $" + deposit);
deposit = deposit + monthly;
System.out.println ("Interest earned for this month:\n");
}
谁能告诉我我做错了什么以及如何解决?干杯