好了,所以我對涉及貸款和信息提供給有關從什麼用戶輸入貸款用戶的程序工作。(Java初學者) - 遇到問題與程序
這個程序我寫的目的是爲用戶被要求輸入貸款金額和年數,他們必須還清。一旦用戶提供了這些信息,該程序將獲取貸款金額和年數,並告知用戶年利率,每月支付和總金額。 此外,如果用戶輸入貸款金額爲-1,程序應該終止。
下面是我的代碼至今:
package Loans;
import java.util.Scanner;
public class Loans {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
double monthlyInterestRate;
double annualInterestRate;
double monthlyPayment;
double total;
double numberOfYears;
double loanAmount;
System.out.println("This program will compute the monthly payments and total payments for a loan amount on interest rates starting at 5%, incrementing by 1/8th percent up to 8%.");
//Formula to Calculate Monthly Interest Rate:
monthlyInterestRate = (annualInterestRate/1200);
//Formula to Calculate Monthly Payment:
monthlyPayment = (loanAmount*monthlyInterestRate);
//Formula To Calculate Annual Interest Rate:
annualInterestRate = (1-(Math.pow(1/(1 + monthlyInterestRate), numberOfYears * 12)));
//Formula To Calculate The Total Payment:
total = (monthlyPayment*numberOfYears*12);
while(true)
{
System.out.println("Please enter in the loan amount.");
double loanAmount = input.nextDouble();
System.out.println("Please enter in the number of years.");
double numberOfYears = input.nextDouble();
System.out.println("Interest Rate: " + annualInterestRate);
System.out.println("Monthly Payment: " + monthlyPayment);
System.out.println("Total Payment: " + total);
}
}
}
這並不編譯,我不知道爲什麼。 (同樣,我是初學者)
我收到的錯誤是在讀取的行「雙loanAmount = input.nextDouble();」和讀取「double numberOfYears = input.nextDouble();」的行。
的第一行中的錯誤說「重複局部變量loanAmount」。
第二行中的錯誤說, 「多個標記在該行 - 行斷點:貸款[行:39] - 主(字符串[]) - 重複局部變量numberOfYears」
任何反饋非常感謝。
請不要將我們鏈接到奇怪的地方。 – Maroun 2014-10-27 13:26:22
你的代碼本來可以很容易地包含在這個問題中 – JonK 2014-10-27 13:28:19
[我如何問及回答作業問題?](http://meta.stackexchange。com/q/10811) – Braiam 2014-10-27 13:28:59