计算存款利息

输入存款金额money、存期year和年利率rate,计算存款利息

公式:interest = money(1+rate)^ year - money
(输出时保留两位小数)

代码:

import  java.util.Scanner;
public  class  Test{
public static void main(String[] args){
int money,year;
double interest,rate;
Scanner in = new Scanner(System.in);

money = in.nextInt();
year = in.nextInt();
rate = in.nextDouble();
interest = money*Math.pow((1+rate),year)-money;
System.out.println("insterest="+(int)(interest*100+0.5)/100.0);
}
}

你可能感兴趣的:(Java)