我想知道爲什麼會出現錯誤,如何修復它爲我的Java項目。DecimalFormat.format方法調用:不兼容的類型
我不得不做出完全一樣了,因爲這些:
- 的年利率什麼是爲小數? (例如:0.045).033
- 多少年內將你的抵押貸款在哪裏舉行? 15
- 你借了多少抵押貸款? 300000
- 數0.033可表示爲3.3%
- 抵押貸款金額爲$ 300,000.00
- 以美元每月支付$ 2,115.30
- 超過以美元年付款總額是$ 380,754.76
- 過度 - 付款是$ 80,754.76超額付款的比例爲 按揭是26.9
這就是我在Eclipse上所做的;
double annIntRat;
int nOY;
int borrowMor;
int M;
double monthPay;
double mIR;
Scanner scnr = new Scanner(System.in);
// Your code should go below this line
System.out.print("What is your annual interest rate as a decimal? (ex 0.045): ");
annIntRat = scnr.nextDouble();
System.out.print("How many years will your mortgage be held? ");
nOY = scnr.nextInt();
System.out.print("What amount of the mortgage did you borrow? ");
borrowMor = scnr.nextInt();
DecimalFormat df = new DecimalFormat("0.0");
System.out.println("\nThe number "+annIntRat+" can be represented as "+df.format((annIntRat)*100)+"%");
NumberFormat defaultFormat = NumberFormat.getCurrencyInstance();
M=defaultFormat.format(borrowMor); //< Here is the error and tells me to change to String.But if I do so, there will be an error down there for monthPay=.....
System.out.println("The mortgage amount is "+M);
mIR=(annIntRat)/12;
monthPay=(mIR * M)/(1-(1/Math.pow(1+mIR,12*nOY)));
可否請你指出什麼問題呢? –
有一個旁邊的「M = defaultFormat.format(borrowMor)」 –