System类

System.currentTimeMillis()

public class D6 {
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        int sum = 0;
        for (long i = 0; i < 1000000000 ; i++) {
            sum += i;
        }
        long endtTime = System.currentTimeMillis();
        System.out.println(endtTime-startTime);

    }
}

返回一个long类型的值,这个值表示当前时间与1970年0点0分0秒的时间差,单位毫秒

System.arraycopy(a,2,b,0,4);

public class D7 {
    public static void main(String[] args) {

        int[] a={1,2,3,4,5,6};//源数组
        int[] b={7,8,9,0,1,2};//目标数组

        System.arraycopy(a,2,b,0,4);
        /*
        a:代表源数组被copy的数组
        2:源原数要copy的位置
        b:目标数组 copy后的数组
        0:起始位置
        4:copy的数量
         */
        for (int i : b) {
            System.out.print(i+"\t");
        }
    }
}

3    4    5    6    1    2    

Random类

在指定的取值范围内随即取数

public class D8 {
    public static void main(String[] args) {
        Random random = new Random();
        System.out.println("生成boolean类型的随即数"+random.nextBoolean());
        System.out.println("生成double类型的随即数"+random.nextDouble());
        System.out.println("生成float类型的随即数"+random.nextFloat());
        System.out.println("生成int类型的随即数"+random.nextInt());
        System.out.println("生成0-10之间的int类型的随即数"+random.nextInt(10));
        System.out.println("生成long类型的随即数"+random.nextLong());

    }
}

生成boolean类型的随即数false
生成double类型的随即数0.528831551344972
生成float类型的随即数0.46862954
生成int类型的随即数953418246
生成0-10之间的int类型的随即数4
生成long类型的随即数3764100507036986488

Process finished with exit code 0

 

2021-03-14 17:08:17

posted @ 2021-03-14 16:57  域明夜  阅读(56)  评论(0)    收藏  举报