Math类的使用方法:点击打开链接
程序KY6_4.java
package Myjava;
public class KY6_4 {
public static void main(String args[]) {
System.out.println (Math.abs (-5.8));
System.out.println (Math.ceil (3.2));
System.out.println (Math.floor (3.8));
System.out.println (Math.round (3.8));
System.out.println (Math.round (3.2));
System.out.println (Math.min (3, 2));
System.out.println (Math.max (Math.PI, 4));
System.out.println (Math.log (7.0));
System.out.println (Math.pow (7,2));
System.out.println (Math.exp (0.4));
System.out.println ("e is:"+ Math.E);
System.out.println ("π is:"+Math.PI);
System.out.println(Math.random());
}
}
运行结果:
5.8
4.0
3.0
4
3
2
4.0
1.9459101490553132
49.0
1.4918246976412703
e is:2.718281828459045
π is:3.141592653589793
0.5699641253238485