作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
public class Interest {
public static void main(String[] args) {
int n; // number of years
double rate; // annual rate
for (int r = 5; r<=10; r++ ) {
System.out.println("\nInterest rate is " + r + "%");
System.out.println("**********************");
System.out.println("Year\tAmount on deposit");
for (n=1; n<=10; n++) {
int p = 1000; // original amount
rate = r / 100;
double a = p * (Math.pow(1 + rate, n)); // amount on deposit at the end of year
System.out.printf("\n%d\t%.2f", n, a);
}
}
}
}
它以年为单位正确显示了图表。但年末存款金额 (a) 保持不变 (1000)。看起来像这样;
Interest rate is 5%
**********************
Year Amount on deposit
1 1000.00
2 1000.00
3 1000.00
4 1000.00
5 1000.00
6 1000.00
7 1000.00
8 1000.00
9 1000.00
10 1000.00
它一直持续到利率达到 10%。
最佳答案
您正在执行 integer division .
尝试:rate = r/100.0;
关于java - 为什么程序不计算利息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20059600/
晚上好!我正在自学编码。现在,我正在制作一个 JavaScript 贷款计算器,但遇到了障碍。如果我输入 0% 的利息,它不会在我的输出文本框中显示任何内容。不过,其他一切都运行良好。任何帮助,将不胜
我是一名优秀的程序员,十分优秀!