每月计算器以获得利息
import java.util.Scanner;
import java.text.DecimalFormat;
public class FutureValues {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("Enter the present value: ");
int value = input.nextInt();
System.out.println("Enter annual interest rate: ");
double rate = input.nextDouble();
double newRate = rate / 1200;
System.out.println("Enter the number of months: ");
int months = input.nextInt();
int i;
for (i = 1; i <= months; i++) {
double newVal = value + (value * newRate);
System.out.println("The future value after " + i + " month is " + newVal);
}
}
}
我试图将其用于程序以将Newval更新为下一个每月存款,但它对我尝试的任何事情都无法使用。
例如。 “ 1个月后的未来价值为1004.79” “ 2个月后的未来价值为1009.61” 等等。我只是无法将其更新到下一个值。
import java.util.Scanner;
import java.text.DecimalFormat;
public class FutureValues {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("Enter the present value: ");
int value = input.nextInt();
System.out.println("Enter annual interest rate: ");
double rate = input.nextDouble();
double newRate = rate / 1200;
System.out.println("Enter the number of months: ");
int months = input.nextInt();
int i;
for (i = 1; i <= months; i++) {
double newVal = value + (value * newRate);
System.out.println("The future value after " + i + " month is " + newVal);
}
}
}
I'm trying to get this to program to update the newVal to the next monthly deposit but it won't work for anything I try.
eg. "The future value after 1 month is 1004.79"
"The future value after 2 months is 1009.61"
and so on and so forth. I just cannot get it to update to the next value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NEWVAL的计算应在循环中完成。
The Calculation of newVal should be done within the loop.