题目是这样的:让用户输入贷款总额及以年为单位的贷款期限,以1/8为递增量,显示从5%到8%的利率下每月支付额和总偿还额。假设输入贷款总量为10000,还贷期限为五年,所显示的输出如下:
贷款总额: 10000
年数: 5
利率         月支付额         总偿还额
5%           188.71           11322.74
5.125%       189.28           11357.13
...
7.85%        202.16           12129.97
8.0%         202.76           12165.83import javax.swing.JOptionPane;public class XiTi4_21{
public static void main(String[] args){
String loanAmountString = JOptionPane.showInputDialog("Enter loan amount");
int loanAmount = Integer.parseInt(loanAmountString);

String yearsString = JOptionPane.showInputDialog("Enter years");
int years = Integer.parseInt(yearsString);

double rate = 0.05;
double currentValue = 0.00125;

String output = "\ndaiKuanJinE: " + loanAmount;
output += "\nnianShu: " + years;
output += "\nrate                mouthlyPayment                totalPayment";

for(int count = 0; count < 24; count++){

double mouthlyPayment = rate * loanAmount / 12 + loanAmount / (5 * 12);
double totalPayment = rate * loanAmount * years + loanAmount;

mouthlyPayment = (int)(mouthlyPayment * 100) / 100.0;
totalPayment = (int)(totalPayment * 100) / 100.0;


output += "\n" + rate + "                " + mouthlyPayment + "                " + totalPayment;
rate += currentValue;
}
JOptionPane.showMessageDialog(null, output);


}
}
我编译运行后发现那个结果跟那题目的结果不一样,很纳闷,那个5%是年利率呢还是什么,还有就是我的程序运行结果的精度问题,是不是要用单精度的浮点数,要怎么表示,最后一个问题就是那个“5%、5.125%”这些要怎么才能在输出端显示出来。希望大家抽出点你们宝贵的时间帮菜鸟的我分析下,谢谢!!