黑马程序员技术交流社区

标题: Math 的基本使用 [打印本页]

作者: aguang    时间: 2015-8-24 08:39
标题: Math 的基本使用
  1. package test;

  2. /*
  3. *Math:数学运算
  4. * 成员变量
  5. * PI  E
  6. *
  7. * 成员方法
  8. *                 public static int abs(int a) 绝对值
  9. *                 public static double ceil(double a)  向上取整
  10. *                 public static double floor(double a) 向下取整
  11. *                 public static  int max(int a,int b)
  12. *                 public static int min (int a,int b)
  13. *                 public static double pow(double a,double b)  a的b次幂
  14. *                 public static double random(); [0.0-1.0)
  15. *                 public static int round(float)  参数为double   四舍五入
  16. *                 public static double sqrt(double a)  正平方根
  17. *                
  18. * */

  19. public class Test01 {
  20.         public static void main(String[] args) {
  21.                 System.out.println(Math.PI);
  22.                 System.out.println(Math.E);
  23.                
  24.                 //abs
  25.                 System.out.println(Math.abs(-10));
  26.                 //ceil
  27.                 System.out.println(Math.ceil(12.34));
  28.                 //floor
  29.                 System.out.println(Math.floor(12.34));
  30.                 //max
  31.                 System.out.println(Math.max(12,33));
  32.                 System.out.println(Math.max(12, Math.max(14, 44))); //方法嵌套调用
  33.                 //pow
  34.                 System.out.println(Math.pow(2,3));
  35.                 //round
  36.                 System.out.println(Math.round(12.63));
  37.                 System.out.println(Math.round(12.11));
  38.                 //sqrt
  39.                 System.out.println(Math.sqrt(4));
  40.         }
  41. }


























复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2