点评:当须要进行求幂、求绝对值、四舍五入、cos、sin、log等等数学运算时,咱们应使用Math类的方法。 dom
//方法具体用法请参看API,唉,懒得敲了。
public class MathDemo { .net
public static void main(String[] args) {
test();
}
/**
* Math经常使用方法:
* 求绝对值,
* 求ceil或floor最接近整数,
* 求幂,
* 求随机数,
* 四舍五入,
* sin、cos、log等值
* ……
* 重载方法:abs(...),ceil(double a),floor(double a) ,max(...,...),min(...,...),pow(double a, double b)
random() ,rint(double a) get
* @param
* @return void
* @Date 2013-10-26上午09:59:59
*/
public static void test() {
System.out.println(Math.ceil(3.14)); //4
System.out.println(Math.floor(3.14)); //3
System.out.println(Math.ceil(-3.14)); //-3
System.out.println(Math.floor(-3.14)); //-4
//四舍五入
System.out.println(Math.rint(5.5));
}
} 数学