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 =借入的金额(贷款额)
i =每月利率(Mintrate)
n =付款次数
我尝试了以下但我无法弄明白
monp = Loanamount [Mintrate(1+ Mintrate)^n] / [(1+ Mintrate)^n-1 ];
答案 0 :(得分:1)
Math.pow
是您需要的,而不是^
。您也无法使用[
或]
。您必须使用括号(
和)
。
更多数学函数可在以下位置找到:
http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html
答案 1 :(得分:1)
您需要在此处使用Math.pow
effectivley。
尝试在代码中使用以下内容
monp = Loanamount*(Mintrate*Math.pow((1+ Mintrate),n)) / (Math.pow((1+ Mintrate),n-1 ) ;
答案 2 :(得分:1)
^
的方法在Java中称为Math.pow(double a, double b);
。
a
是要筹集b
次的数字。
您的公式看起来像monp = Loanamount Math.pow((Mintrate(1+ Mintrate), n)) / (Math.pow((1+ Mintrate), n-1));
答案 3 :(得分:0)
你需要调用Math.pow(double,double)
或者您可以将所需的类导入为..
import static java.lang.Math.pow;
然后使用pow()函数