Math类是数学操作类,提供了一系列的数学操作方法。
在Math类中提供的一切方法都是静态方法,所以直接由类名称调用即可。
//=================================================
// File Name : Math_demo
//------------------------------------------------------------------------------
// Author : Common
import java.lang.Math;;
public class Math_demo {
public static void main(String[] args) {
// TODO 自动生成的方法存根
//Math类中的方法都是静态方法,直接使用“类名称.类方法()”的形式调用即可
System.out.println("求平方根:"+Math.sqrt(9.0));
System.out.println("求最大值:"+Math.max(10,30));
System.out.println("求最小值:"+Math.min(10,30));
System.out.println("2的3次方:"+Math.pow(2,3));
System.out.println("四舍五入:"+Math.round(10.1));
}
}