2015-10-21 55 views
0
package methods; 
import java.util.Scanner; 

/** 
* 
* @author Billy 
*/ 
public class Methods { 

/** 
* @param args the command line arguments 
*/ 
    public static void main(String[] args) {  
    double Loanamount; // Loan amount from user 
    double Aintrate; // User's annual interest rate 
    double months; // Number of months on loan 
    double monp; // Monthly payment 
    double Mintrate; // Monthly interest rate 
    double n; // The number of payments 


    // declare an instance of Scanner to read the datastream from the keyboard. 
    Scanner kb = new Scanner(System.in); 

    // Get user's loan amount 
    System.out.print("Please enter your total loan amount: "); 
    Loanamount = kb.nextDouble(); 

    // Get user's interest rate 
    System.out.print("Please enter your annual interest rate as a decimal: "); 
    Aintrate = kb.nextDouble(); 

    // Get user's number of months 
    System.out.print("Please enter the number of months left on your loan: "); 
    months = kb.nextDouble(); 

    // Calculate montly interest rate 
    Mintrate = ((Aintrate/12)); 

     System.out.println("Your monthly interest rate is " + " " + Mintrate); 

    // Calculate number of payments 
     n = ((months * 12)); 

    // Calculate monthly payment 

我的下一个工作是找出每月付款使用这个公式。努布需要一些帮助实施一个公式

M = P [I(1 + I)^ N]/[(1 + I)^ N - 1]

M =每月按揭付款
P =借用(Loanamount)的量
I =每月利率(Mintrate)
N =支付次数

我尝试以下,但我只是不能想出办法来
​​

+0

使用'Math.pow',这就是你正在寻找的,而不是''''','''''''''''''','''''''''''''',''''''''''''','''''',''''''''''''''''''''''''''''''''',''''''''''''''''',''''''''''''''''''''''''''''还有,你的代码应该包括这个形式, – SomeJavaGuy

+0

如果使用'double'类型仍然足以进行估计,则由于舍入误差,它不应该用于财务计算。 –

回答

1

您需要使用Math.pow这里有效。

尝试在你的代码

monp = Loanamount*(Mintrate*Math.pow((1+ Mintrate),n))/(Math.pow((1+ Mintrate),n-1) ; 
+0

非常感谢:) – archer

+0

@archer很高兴帮助 –

1

^的方法是在Java中称为Math.pow(double a, double b);使用以下。

其中a是要提高的数字b次。

那么你的公式看起来像monp = Loanamount Math.pow((Mintrate(1+ Mintrate), n))/(Math.pow((1+ Mintrate), n-1));

Reference

0

你需要调用Math.pow(双,双)

,或者你可以导入所需的类作为..
import static java.lang.Math.pow;
然后使用pow()函数