Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我不知道';我不知道如何显示我的计算结果_Java - Fatal编程技术网

Java 我不知道';我不知道如何显示我的计算结果

Java 我不知道';我不知道如何显示我的计算结果,java,Java,此程序允许用户以年数输入贷款金额和贷款期限 每月和总付款应以1/8的利率递增显示。到目前为止,我已经得到足够多的正确计算一个金额,但我不知道如何显示所有的结果 我拍摄了以下问题说明的照片: import java.util.Scanner; 计算机类 { 公共静态void main(字符串[]args) { 扫描仪输入=新扫描仪(System.in); //输入年数 System.out.print(“以整数形式输入年份:”); int numberOfYears=input.nextInt(

此程序允许用户以年数输入贷款金额和贷款期限

每月和总付款应以1/8的利率递增显示。到目前为止,我已经得到足够多的正确计算一个金额,但我不知道如何显示所有的结果

我拍摄了以下问题说明的照片:

import java.util.Scanner;
计算机类
{
公共静态void main(字符串[]args)
{
扫描仪输入=新扫描仪(System.in);
//输入年数
System.out.print(“以整数形式输入年份:”);
int numberOfYears=input.nextInt();
//输入贷款金额
系统输出打印(“输入贷款金额:”);
double loanAmount=input.nextDouble();
//申报利率
双倍利率=5.000;
//获得月利率
双月利率=利率/1200;
//计算付款
双月付款=贷款金额*月利息/(1-1/数学功率(1+月利息,年数*12));
双倍总付款=月付款*年数*12;

for(double intRate=5.000;intRateHello请尝试这样在for循环中进行计算

import java.util.Scanner;

class ComputeLoan

{
public static void main(String[] args) 
{
    Scanner input = new Scanner(System.in);

    //Enter number of years
    System.out.print("Enter number of years as an integer: ");
        int numberOfYears = input.nextInt();

    //Enter loan amount
    System.out.print("Enter Loan amount: ");
    double loanAmount = input.nextDouble();


    for (double intRate=5.000; intRate <8.000; intRate = intRate + .125)
    {

    //Obtain monthly interest rate
    double monthlyInterestRate = intRate / 1200;

    //Calculate payment

    double monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 /                                                              Math.pow(1 + monthlyInterestRate, numberOfYears * 12));

double totalPayment = monthlyPayment * numberOfYears * 12;
    System.out.println("The InterestRate is " + intRate);
    System.out.println("The monthly payment is $" +
        (int)(monthlyPayment * 100) / 100.0);
    System.out.println("The total payment is $" +
        (int)(totalPayment * 100) / 100.0);


} 
}
}

查看您链接到的图像,我猜您正在尝试为每一列提供相等的空间。
System.out.printf()
String.format()
是您可能感兴趣的函数

下面的代码将第一个十进制数四舍五入(视情况向上或向下)为3位,第二个和第三个十进制数四舍五入为2位。每列包含20个空格

    System.out.printf("%20s%20s%20s", 
            "Interest Rate", "Monthly Payment", "Total Payment");
    System.out.printf(%20.3f%20.2f%20.2f,
            intRate, monthlyPayment, totalPayment);

这有助于我显示1个结果,但我需要它以1/8的增量显示5到8之间的每个结果。示例在我发布的链接中。我是否必须为每个结果创建单独的循环?intRate变量以1/8的增量递增,但它只显示第一个值5。尝试运行此代码,我删除了不必要的分号,即nd已经运行了我自己,为我工作。用我的输出更新了答案抱歉,回答有点晚,但这确实有效。谢谢大家的帮助!你的代码目前输出什么?现在它输出:利率是:5.0月付款是118.71美元,总付款是11322.74美元。所有这些都是正确的,但我正在尝试分配为每个变化的利率显示结果在for循环的末尾有一个额外的分号:
for(double intRate=5.000;intRate
Enter number of years as an integer: 5
Enter Loan amount: 10000
The InterestRate is 5.0
The monthly payment is $188.71
The total payment is $11322.74
The InterestRate is 5.125
The monthly payment is $189.28
The total payment is $11357.13
The InterestRate is 5.25
The monthly payment is $189.85
The total payment is $11391.59
The InterestRate is 5.375
The monthly payment is $190.43
The total payment is $11426.11
The InterestRate is 5.5
The monthly payment is $191.01
The total payment is $11460.69
The InterestRate is 5.625
The monthly payment is $191.58
The total payment is $11495.34
The InterestRate is 5.75
The monthly payment is $192.16
The total payment is $11530.06
The InterestRate is 5.875
The monthly payment is $192.74
The total payment is $11564.83
The InterestRate is 6.0
The monthly payment is $193.32
The total payment is $11599.68
The InterestRate is 6.125
The monthly payment is $193.9
The total payment is $11634.58
The InterestRate is 6.25
The monthly payment is $194.49
The total payment is $11669.55
The InterestRate is 6.375
The monthly payment is $195.07
The total payment is $11704.59
The InterestRate is 6.5
The monthly payment is $195.66
The total payment is $11739.68
The InterestRate is 6.625
The monthly payment is $196.24
The total payment is $11774.85
The InterestRate is 6.75
The monthly payment is $196.83
The total payment is $11810.07
The InterestRate is 6.875
The monthly payment is $197.42
The total payment is $11845.36
The InterestRate is 7.0
The monthly payment is $198.01
The total payment is $11880.71
The InterestRate is 7.125
The monthly payment is $198.6
The total payment is $11916.13
The InterestRate is 7.25
The monthly payment is $199.19
The total payment is $11951.61
The InterestRate is 7.375
The monthly payment is $199.78
The total payment is $11987.16
The InterestRate is 7.5
The monthly payment is $200.37
The total payment is $12022.76
The InterestRate is 7.625
The monthly payment is $200.97
The total payment is $12058.44
The InterestRate is 7.75
The monthly payment is $201.56
The total payment is $12094.17
The InterestRate is 7.875
The monthly payment is $202.16
The total payment is $12129.97
    System.out.printf("%20s%20s%20s", 
            "Interest Rate", "Monthly Payment", "Total Payment");
    System.out.printf(%20.3f%20.2f%20.2f,
            intRate, monthlyPayment, totalPayment);