import java.util.Scanner;
public class xt2_21 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter investment amount: ");
double touzizonge = input.nextDouble();
System.out.print("Enter annual interest rate in percentage: ");
double nianlilv = input.nextDouble(); // 注意此处需要除以1200而不是12,因为用户输入的年利率是不带百分号的
double yuelilv = nianlilv / 1200;
System.out.print("Enter number of years: ");
double year = input.nextDouble();
double year12 = year * 12;
double weilaijine = touzizonge * Math.pow(1 + yuelilv,year12);
System.out.println("Accumulated value is $" + weilaijine);
}
}
java DecimalFormat fromat的使用 你就会明白了