java.util.Arrays

package ne;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class c6 {
    public static void main(String[] args) {
        //Arrays.fill()、Arrays.toString()、Arrays.sort()、Arrays.deepToString(nums)

        Integer[] n1 = {1, 2, 3};
        System.out.println(n1);
//数组转换为List
        List ints = Arrays.asList(n1);
        System.out.println(ints);
//asList() 返回List
        List list = Arrays.asList(1, 2, 3);
        System.out.println(list);
//fill()
        int[] nn = new int[6];
        System.out.println(Arrays.toString(nn));
        Arrays.fill(nn, 6);
        Arrays.fill(nn, 1, 3, 5);//数组1 2 填充元素值为5
        System.out.println(Arrays.toString(nn));
//stream()
        int sum = 0;
        for (int i : nn) {
            sum += i;
        }
        System.out.println(sum);
        int sum2 = Arrays.stream(nn).sum();
        System.out.println(sum2);
//toString()
        System.out.println(Arrays.toString(nn));
        Integer[] n2 = {1, 22, 333};
        System.out.println(Arrays.deepToString(n2));
        int[][][] n3 = {{{1}}, {{1, 2, 3}}, {{24, 1, 2}, {24}}};
        System.out.println(Arrays.deepToString(n3));


        System.out.printf("======================================\n");

        Random rand = new Random();
        //5次
        for (int x = 0; x < 5; x++) {
//1-32
            int[] reds = new int[6];
            for (int i = 0; i < reds.length; i++) {
                int ball = rand.nextInt(1, 33);
                boolean f = true;
                for (int n : reds) {
                    if (n == ball) {
                        f = false;
                        break;
                    }
                }
                if (f) {
                    reds[i] = ball;
                } else {
                    --i;
                }
            }
            Arrays.sort(reds);
            //1-16
            int blue = rand.nextInt(1, 17);
//System.out.println("红:" + Arrays.toString(reds) + "蓝:[" + blue + "]");
            System.out.printf("\033[31m %02d %02d %02d %02d %02d %02d\033[0m \033[34m %02d \033[0m%n", reds[0], reds[1], reds[2],
                    reds[3], reds[4], reds[5], blue);
        }


        System.out.printf("=========================\n");


    }
}

你可能感兴趣的:(java,开发语言)