解决方案 »

  1.   

    import java.util.Scanner;
    import java.text.DecimalFormat;public class Test
    {
    public static void main(String[] args)
       {
    // Create an new Scanner
    Scanner input=new Scanner(System.in);//提示每月向账户存入的钱数
    System.out.print("请输入每月存款数:");
    double amount=input.nextDouble();//提示输入年利率
    System.out.print("请输月利率(0.00417):");
    double monthlyInterestRate=input.nextDouble();
     
    //提示输入要查看的月数
    System.out.print("请输入月份:");
    int monthOfNumbers=input.nextInt();//计算某个月后账户上的钱数
    double  allMoney=(amount+(amount*(1+monthlyInterestRate))*(monthOfNumbers-1))*(1+monthlyInterestRate);
    String sal = new DecimalFormat("#.000").format(allMoney);//输出结果
    System.out.printf(monthOfNumbers+"个月后你的账户上的存款是:" +"   "+sal);
       }
    }
    这是我又重新改进后的程序,还是达不到题目的要求!!!!
      

  2.   

    double  allMoney=0;
    for(int i=0;i<monthOfNumbers;i++)
    allMoney=(allMoney+amount)*(1+monthlyInterestRate);
    表示monthOfNumbers个月之后的钱
      

  3.   

    精确计算,不要用double,用bigdecimal类
      

  4.   

    楼主要学会贴代码public class Demo {
        public static void main(String[] args) {
            if (args.length == 0) {
                System.out.println("no args.");
            }
        }
    }
      

  5.   

    public class Textt { public static void main(String[] args) {
    demo(3,0.05,100); } private static void demo(int time, double lilv,double money) {
    if(time > 0 && lilv > 0 && money > 0){//判断一下信息是不正常的
    double a=money;//记录你要每个月要存储的钱数
    for (int k = 0; k < time; k++) {
    if(k==0){
    money=(money)*(1+lilv/12);
    }else{//从第二个月的话,每月都要往里面加钱
    money=(a+money)*(1+lilv/12);
    }
    }
    System.out.println(money);
    }else{
    System.out.println("输入有误!!!");
    }
    }}
    这是我写的一个小测试,没有添加Scanner功能,你看一下或许有点帮助
      

  6.   


    import java.util.Scanner;
    public class CalculationCompoundInterest {
    public static void main(String[] args) {
    double YEAR_RATE = 0.05;
    double monthRate = YEAR_RATE/12;
    System.out.println("Please input your money:");
    Scanner input = new Scanner(System.in);
    double money = input.nextDouble();
    System.out.println("How many months do you want to store?");
    int month = input.nextInt();
    double totalMoney = 0.0;
    for(int i = 1;i<=month;i++){
    totalMoney = (money+totalMoney)*(1+monthRate);
    }
    System.out.printf("After%2d months,your total money will be:$%7.3f", month,totalMoney);
    input.close();
    }
    }
      

  7.   


    /*
     * 计算任意月的连本带利的值
     * 比如月利率是r,本金是a,月数为m,连本带利的和为x
     * 则第一个月后 x = a(1+r);
     *  第二个月后x = (a(1+r)+a)(1+r)= a[(1+r)^2 + (1+r)];
     *  第三个月后x = [a[(1+r)^2 + (1+r)]](1+r) = a[(1+r)^3 + (1+r)^2 + (1+r)];
     *  第m个月后x = a[(1+r)^m + (1+r)^(m-1) + (1+r)^(m-2) + .... + ()]
     *          = a[(1+r)((1+r)^m-1)]/r
     * 最后这一步利用等比数列求值公式。
     * 把 amount--> a,  monthlyInterestRate-->r,  monthOfNumbers--> m替换后就是代码的公式。
    */
    double  allMoney = amount * (1 + monthlyInterestRate) * (Math.pow(1 + monthlyInterestRate, monthOfNumbers) - 1) / monthlyInterestRate;
      

  8.   

    import java.util.ArrayList;
    import java.util.List;public class Test2 {
    //递归调用
    //第一个参数为 起始存入  第二个参数为  月份
    public static double dox(double money,int mouth){
    if(mouth==1){
    return money*(1+0.00417);
    }
    return (money+dox(money,mouth-1))*(1+0.00417);
    }

    //测试
    public static void main(String[] args) {
    System.out.println(dox(100,2));
    }
    }