Math类的方法应用

 1 class Mortgage
 2 {
 3 public static void main(String[]args)
 4     {
 5     double P=Double.parseDouble(args[0]);
 6     double rate=Double.parseDouble(args[1]);
 7     double R=rate/(12*100);
 8     int N=Integer.parseInt(args[2])*12;
 9     double C=P*(R/(1-Math.pow((1+R),-N)));
10     System.out.print(Math.floor(C));//Math.floor(double a)返回小于等于参数的最大整数
11     
12     /*
13     Math类的方法:
14     1,Math.ceil(double c);表示返回大于等于参数的最小整数。
15     2,Math.floor(double c);表示返回小于等于参数的最大整数。
16     3,Math.rint(double c);表示返回与参数最接近的两个整数。
17     4,Math.round(float c);表示将参数加上0.5后返回最近的整数。
18     5,Math.round(double c);表示加上0.5后返回最近的整数,并强制转换为long整型。
19     */
20     new Mortgage().getMoney(3000.0,1,6.5);//调用方法
21     }
22     //定义每月还款额度的方法
23     public void getMoney(double principal,int years,double rate)
24     {
25      int N=years*12;
26      double R=rate/(12*100);
27      double EvMoney=principal*(R/(1-(Math.pow((1+R),-N))));
28      System.out.print("应按揭每月还款为:"+EvMoney);
29     }
30     
31 }

 

posted on 2014-03-31 17:43  java菜鸟---板砖  阅读(327)  评论(0编辑  收藏  举报

导航