要求写一个程序,求出每月的还贷额度..
M=每月的支付额度
P=首付
I=每年的利息
i=每月的利息,I/12
N=还贷的总年限
n=总分期,12*N个月.M=(P*i*((1+i)^n))/((1+i)^n)-1本人原程序如下:/**
*
*
*/
package exam3;import java.util.*;
public class SmithPayment {
public static void main(String[] args) {
int P,I,N,n,k;
double i,M;
I=0;
N=0;
k=1;
Scanner stdin = new Scanner(System.in);
System.out.println("Please enter the Principal: ");
P = stdin.nextInt();
System.out.println("Please enter the Interest Rates: ");
I = stdin.nextInt();
System.out.println("Please enter the Number of years: ");
N = stdin.nextInt();
i = I/12;
n = 12*N;
M=1;
double temp = 1;
for(k=1; k<n;k++){
temp=temp*(i+1);
}
System.out.println("P: "+P+" I: "+I+" N: "+N+" M: "+M+" i: "+i+" n: "+n+" temp: "+temp+" k: "+k); //之前自己用来检测变量值的,最后要删掉这句.
M=(P*i*temp)/temp-1;
System.out.println("The monthly Payment is : " + M);
}
}
现在程序运行完毕,总是有错误,不对!
要求输入Please enter the Principal:
100000
Please enter the Interest Rates:
5
Please enter the Number of years:
20输出结果
The monthly Payment is : $659.96请大虾帮助!@!
M=每月的支付额度
P=首付
I=每年的利息
i=每月的利息,I/12
N=还贷的总年限
n=总分期,12*N个月.M=(P*i*((1+i)^n))/((1+i)^n)-1本人原程序如下:/**
*
*
*/
package exam3;import java.util.*;
public class SmithPayment {
public static void main(String[] args) {
int P,I,N,n,k;
double i,M;
I=0;
N=0;
k=1;
Scanner stdin = new Scanner(System.in);
System.out.println("Please enter the Principal: ");
P = stdin.nextInt();
System.out.println("Please enter the Interest Rates: ");
I = stdin.nextInt();
System.out.println("Please enter the Number of years: ");
N = stdin.nextInt();
i = I/12;
n = 12*N;
M=1;
double temp = 1;
for(k=1; k<n;k++){
temp=temp*(i+1);
}
System.out.println("P: "+P+" I: "+I+" N: "+N+" M: "+M+" i: "+i+" n: "+n+" temp: "+temp+" k: "+k); //之前自己用来检测变量值的,最后要删掉这句.
M=(P*i*temp)/temp-1;
System.out.println("The monthly Payment is : " + M);
}
}
现在程序运行完毕,总是有错误,不对!
要求输入Please enter the Principal:
100000
Please enter the Interest Rates:
5
Please enter the Number of years:
20输出结果
The monthly Payment is : $659.96请大虾帮助!@!
解决方案 »
- 写一个ArrayList类的代理,实现和ArrayList中完全相同的功能,并可以计算每个方法运行的时间。
- Exception in thread "main" java.lang.Error: 无法解析的编译问题:
- 谁能给我一个完整的GUI示例代码?
- 请高手帮我看一下这段代码,有关Map的使用。
- 线程同步的问题
- 急急急急!在c通过jni调用java过程中遇到的麻烦,麻烦各位帮帮忙
- 最近总是不想看书
- 求一个GUI布局的小项目
- 技术问题:如何做一个类似于蚂蚁的拖放监视窗口?
- 如此菜鸟,那里要?!
- 关于文件读入的问题?急!!!
- The Network Adapter could not establish the connection
The monthly Payment is : $659.96 这个是要求的输出结果,但是上面我的源程序输出的并不是这个结果...
源程序有地方有错误,我想主要是那个求(1+i)^n这出问题了,我不知道这个循环该怎么弄,希望大侠能帮我纠正.@!@
非常感谢你的解答!@!/**
*
*
*/
package exam3;import java.util.*;
public class SmithPayment {
public static void main(String[] args) {
int P,N,n,k;
double i,M,I,InputI;
N=0;
k=1;
Scanner stdin = new Scanner(System.in);
System.out.println("Please enter the Principal: ");
P = stdin.nextInt();
System.out.println("Please enter the Interest Rates: ");
InputI = stdin.nextInt();
I=InputI/100;
i = I/12;
System.out.println("Please enter the Number of years: ");
N = stdin.nextInt();
n = 12*N;
M=1;
double temp = 1;
for(k=1; k<n;k++){
temp=temp*(i+1);
}
M=(P*i*temp)/(temp-1);
System.out.println("The monthly Payment is : " + M);
}
}