篮球群随机组队打比赛

206 阅读1分钟
import java.util.*;

public class ChouQian {
    public static void main(String[] args) {
        String[] names = {
                "徐浪", "楚虎", "顾浩", "大帅比", "牛超", "纹身哥", "金多", "大鹏", "袁铭", "魏陆军", "翘臀哥", "乐飞翔", "射手大哥",
                "刘伟", "杜兰特", "施盛伟", "邵邵", "佳乐", "流川枫", "斯玛特", "A杨洋", "钱震", "小射手", "郭龙", "尹明阳", "小涛",
                "君华", "李庆", "庄猛", "李玉龙", "康SIR", "教练", "阿强", "球星", "吉祥", "武王", "陈佳瑞", "张超", "挑王", "王城"
        };
        Collections.shuffle(Arrays.asList(names));
        List<List<String>> lists = splitArr(names, 4);
        for (List<String> list : lists) {
            System.out.println(list.toString());
        }
    }
    private static List<List<String>> splitArr(String[] array, int num){
        int count = array.length % num == 0 ? array.length / num : array.length / num + 1;
        List<List<String>> arrayList = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            int index = i * num;
            List<String> list = new ArrayList<>();
            int j = 0;
            while (j < num && index < array.length) {
                list.add(array[index++]);
                j++;
            }
            arrayList.add(list);
        }
        return arrayList;
    }
}

1660544463828.png