黑马程序员技术交流社区
标题:
Math 的基本使用
[打印本页]
作者:
aguang
时间:
2015-8-24 08:39
标题:
Math 的基本使用
package test;
/*
*Math:数学运算
* 成员变量
* PI E
*
* 成员方法
* public static int abs(int a) 绝对值
* public static double ceil(double a) 向上取整
* public static double floor(double a) 向下取整
* public static int max(int a,int b)
* public static int min (int a,int b)
* public static double pow(double a,double b) a的b次幂
* public static double random(); [0.0-1.0)
* public static int round(float) 参数为double 四舍五入
* public static double sqrt(double a) 正平方根
*
* */
public class Test01 {
public static void main(String[] args) {
System.out.println(Math.PI);
System.out.println(Math.E);
//abs
System.out.println(Math.abs(-10));
//ceil
System.out.println(Math.ceil(12.34));
//floor
System.out.println(Math.floor(12.34));
//max
System.out.println(Math.max(12,33));
System.out.println(Math.max(12, Math.max(14, 44))); //方法嵌套调用
//pow
System.out.println(Math.pow(2,3));
//round
System.out.println(Math.round(12.63));
System.out.println(Math.round(12.11));
//sqrt
System.out.println(Math.sqrt(4));
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2