方法名 | 说明 |
---|---|
public static int abs(int a) | 获取参数绝对值 |
public static double ceil(double a) | 向上取整 |
public static double floor(double a) | 向下取整 |
public static int round(float a) | 四舍五入 |
public static max(int a,int b) | 获取两个int值中较大的值 |
public static double ppow(double a,double b) | 返回a的b次幂的值 |
public static double random() | 返回值为double的随机值,范围[ 0.0,1.0 ] |
public class Test {
public static void main(String[] args) {
// 目标:了解Math类提供的常见方法
System.out.println(Math.abs(12)); //12
System.out.println(Math.abs(-12)); //12
System.out.println(Math.ceil(4.0001)); //5.0
System.out.println(Math.ceil(4.0)); //4.0
System.out.println(Math.floor(4.999)); //4.0
System.out.println(Math.floor(4.0)); //4.0
System.out.println(Math.round(3.499)); //3
System.out.println(Math.round(3.5001)); //3
System.out.println(Math.max(10,20)); //20
System.out.println(Math.min(10,20)); //10
System.out.println(Math.pow(2,3)); //8.0
System.out.println(Math.pow(3,2)); //9.0
System.out.println(Math.random());
}
}
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException, InterruptedException {
// 目标:了解Runtime类提供的常见方法
//返回与当前Java应用程序关联的运行时对象
Runtime r = Runtime.getRuntime();
//终止当前运行的虚拟机
//r.exit(0);
//返回Java虚拟机可用的处理器数
System.out.println(r.availableProcessors());
//返回Java虚拟机中的内存总量
System.out.println(r.totalMemory() / 1024.0 / 1024.0 + "MB");
//返回Java虚拟机中的可用内存
System.out.println(r.freeMemory() / 1024.0 / 1024.0 + "MB");
//启动某个程序,并返回代表该程序的对象
Process p = r.exec("D:\\数据库\\Navicat Premium 16\\navicat.exe");
Thread.sleep(5000); //让程序在这里暂停5s后继续往下走
p.destroy(); //销毁!关闭程序
}
}
?