该程序允许用户以年数输入贷款金额和贷款期限。
每月和总付款应以1/8的利率递增显示。到目前为止,我已经足够正确地计算出一个数量,但我不知道如何显示所有结果。
我拍摄了以下问题的说明:
http://imgur.com/s9JEbtu
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();
//Declare interest rate
double interestRate = 5.000;
//Obtain monthly interest rate
double monthlyInterestRate = interestRate / 1200;
//Calculate payment
double monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12));
double totalPayment = monthlyPayment * numberOfYears * 12;
for (double intRate=5.000; intRate <8.000; intRate = intRate + .125);
{
double intRate=5.000;
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);
}
//Display Results
}
}
看看你把我们链接到的图片,我猜你是在给每一列留出相等的空间<代码>系统。出来printf()和字符串。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);
你好,试试这样计算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);
}
}
}
输出是
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
(我已经删除了上一个,所以我想你可以在编辑中找到它) 编辑 所以按照bad_coder在评论中告诉的以及他分享的链接中的大多数答案,我点击了“选项显示所有”,我得到了这个 1) 这里唯一有意义的是点击“”按钮,所以我点击了它 2) 现在我应该用路径替换突出显示的部分(换句话说,我在cmd中键入“where python”后得到的路径) 3) 这就是我发现的。那么我应该在突出显示的部分复制并粘贴哪一
我已经调试这段代码好几个小时了,试图让输出正确无误。它在早期工作,但输出中存在逻辑错误,因此我进入并在输出函数中添加了循环和一个额外参数。 现在g给我以下错误: Student.cpp:在成员函数“void Student::input data(std::string,int,STD::string 如何修复此代码?:
我是机器人和爪哇的新手。我已经构建了一个计算器,当我输入3个输入时,我需要它来自动显示结果,但我不知道该怎么做。 我将multiply添加到了一个文本视图(通过属性onclick),它可以工作,但我希望它能在textview中自动显示。
嗨,我发现了这个使用注释的pdfbox示例: https://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/addannotations.java 当我尝试在netbeans中运行它时,除了在输出中打印之外,什么也没有发生:
我的程序声明了两个大小为26的字符数组(char[26]),从包含a-z和a-z的字符串中随机获取字母,并使用它们填充这两个数组。最后,它从两个数组中获取每个小写字母,然后使用它们填充一个ArrayList,按字母顺序排序,然后显示(或者至少应该这样做)。我不是完全确定问题是什么,更不知道如何解决它,所以任何帮助将是感激的。
我想使用ItemTouchHelper类,它应该在android Studio的标准安装中可用(所以我在互联网上写了)。 无论如何,当我尝试使用这个类时,我会收到一条错误消息。你们可以在图片中看到。错误帮助程序未知 我能做什么,分别实现必要的库ItemTouchHelper类。 请用简单的语言描述,并尽可能详细地描述,因为我是一个绝对的Android初学者:) 我很高兴能找到解决方案! 向费边致意