Math,System,Runtime(JAVA)

Math,System,Runtime(JAVA)

Math

方法名说明
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 int max(int a,int b)获取两个int值中较大的值
public static double pow(double a,double b)返回a的b次幂的值
public static double random()返回值为double的随机值,范围[0.0,1.0]

System

方法名说明
public static void exit(int status)终止当前运行的java虚拟机
public static long currentTimeMills()返回当前系统的时间毫秒值形式
public static void arraycopy(数据源数组,起始索引,目的地索引,起始索引,拷贝个数)数组拷贝

public static void exit(int status)

形参是状态码

0:表示虚拟机是正常停止

非0:表示虚拟机是异常停止

Systemexit();

public static long currentTimeMills()

1970年1月1日 08:00:00是东八区的时间原点

long l = System.currentTimeMills();
System.out.println(l);

输出的数表示从时间原点到程序运行的时间点,用毫秒的形式表示出来

public static void arraycopy(数据源数组,起始索引,目的地数组,起始索引,拷贝个数)

将arr1数组的内容拷贝到arr2中

int[] arr1 = {1,2,3,4,5,6,7,8,9,10};
int[] arr2 = new int[10];
System.arraycopy(arr1,0,arr2,0,10);
for(int i = 0;i<arr2.length;i++){
    System.out.print(arr2[i]+" ");
}

在这里插入图片描述

注意:

  1. 如果数据源数组和目的地数组的都是基本数据类型,那么两者的数据类型必须保持一致,否则报错
  2. 在拷贝的时候需要考虑数组的长度,如果超出范围也会报错
  3. 如果数据源数组和目的地数组都是引用数据类型,那么子类型可以赋值给父类类型,但是必须要要经过类型转换

Runtime

Runtime表示当前虚拟机的运行环境

方法名说明
public static Runtime getRuntime()当前系统的运行环境
public void exit(int status)停止虚拟机
public int availableProcessors()获得CPU的线程数
public long maxMemory()JVM能从系统中获取总内存的大小(单位byte)
public long totalMemory()JVM已经从系统中获取总内存的大小(单位byte)
public long freeMemory()JVM剩余内存大小(单位byte)
public Process exec(String comand)运行cmd命令

public static Runtime getRuntime()

Runtime r1 = Runtime.getRuntime();

表示获取当前的虚拟机,不管在哪个类里面调用Runtime都是获取的同一个对象

public void exit(int status)

Runtime r1 = Runtime.getRuntime();
r1.exit(1);

0:表示正常停止

非0:表示异常停止

//可以写成一下方式
Runtime.getRuntime.exit(0);

public int availableProcessors()

System.out.println(Runtime.getRuntime().availableProcessors());

public long maxMemory()

System.out.println(Runtime.getRuntime().maxMemory());

public long totalMemory()

System.out.println(Runtime.getRuntime().totalMemory());

public long freeMemory()

System.out.println(Runtime.getRuntime().freeMemory());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

都不会的鲨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值