Java 1年、3年和5年后的复利
我有一个计算复利的代码,但我需要它来计算1年、3年和5年后的复利。我试过了,但似乎无法使它发挥作用。有人能帮我吗Java 1年、3年和5年后的复利,java,math,calculator,rate,Java,Math,Calculator,Rate,我有一个计算复利的代码,但我需要它来计算1年、3年和5年后的复利。我试过了,但似乎无法使它发挥作用。有人能帮我吗 import java.util.Scanner; public class CompoundInterest { public static void main(String[] args) { Scanner input = new Scanner(System.in); double principal = 0; double rate = 0; double
import java.util.Scanner;
public class CompoundInterest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double principal = 0;
double rate = 0;
double time = 0;
double x = 0;
System.out.print("Enter the amount invested : ");
principal = input.nextDouble();
System.out.print("Enter the Rate of interest : ");
rate = input.nextDouble();
System.out.print("Enter the Time of loan : ");
time = input.nextDouble();
x = principal * Math.pow((1 + rate/12),time);
x = Math.pow(5,3);
System.out.println("");
System.out.println("The Compound Interest after 1 year is : "
+ x);
}
}
为什么要将
x
设置为principal*((1+r/12),time)
,然后设置x=math.pow(5,3)
x
现在设置为math.pow(5,3)
,与您输入的本金、利率和时间无关
此外,您应该指定时间输入为年,因为您在费率问题中有硬编码 不,不,这是几个月,而不是几年,为这工作;但是+1表示正确答案。