Math类是一个数学操作的类,Math类中的方法都是静态方法,直接使用“类.方法名称()”的形式调用即可
public class MathDemo {
public static void main(String args[]){
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(33.6)) ;
}
}
程序运行结果:


本文介绍Java中Math类的常用数学操作方法,包括求平方根、最大值、最小值、幂运算及四舍五入等。通过实例演示如何在程序中应用这些方法。
11万+

被折叠的 条评论
为什么被折叠?



