點評:當須要進行求冪、求絕對值、四捨五入、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));
}
} 數學