java随机排座位

//打乱学生顺序

Collections.shuffle();

容我记个单词

peer:

vi.
凝视; 盯着看; 隐退,若隐若现; 同等,比得上;
n.
同辈,同等的人; 贵族; 同伴,伙伴;
adj.
贵族的; (年龄、地位等)同等的; 相匹敌的;

 PEER-TO-PEER:同等延迟机制。根据网络中共享资源方式的不同,局域网有两种组织形式

package com.itzerone.name;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class SortTeam {

public static void main(String[] args) {

// 学生集合
List<String> student = new ArrayList<String>();
// 学生数据
String[] names = { “xxX”,"xxx","xxx","xxxx","xxx","xxx" };

// 遍历
for (String stuNum : names) {
student.add(stuNum);

}
// 打乱学生顺序
Collections.shuffle(student);

// 学生41人,5人一组,留1人
List<String> one = new ArrayList<String>();// 一个人一组的人
Random random = new Random();
int index = random.nextInt(student.size());
String oneStu = student.remove(index);
one.add(oneStu);

// 41人除去1人还有40人
// 把每组的人存在List集合
List<String> oneTeam = new ArrayList<String>();// 一组
List<String> twoTeam = new ArrayList<String>();// 二组
List<String> threeTeam = new ArrayList<String>();// 三组
List<String> fourTeam = new ArrayList<String>();// 四组
List<String> fiveTeam = new ArrayList<String>();// 五组
List<String> sixTeam = new ArrayList<String>();// 六组
List<String> sevenTeam = new ArrayList<String>();// 七组
List<String> eightTeam = new ArrayList<String>();// 八组

for (int i = 0; i < student.size(); i++) {
// 分配小组
String peploe = student.get(i);
int mod = i % 8;
if (mod == 0) {
oneTeam.add(peploe);
} else if (mod == 1) {
twoTeam.add(peploe);
} else if (mod == 2) {
threeTeam.add(peploe);
} else if (mod == 3) {
fourTeam.add(peploe);
} else if (mod == 4) {
fiveTeam.add(peploe);
} else if (mod == 5) {
sixTeam.add(peploe);
} else if (mod == 6) {
sevenTeam.add(peploe);
} else if (mod == 7) {
eightTeam.add(peploe);
}
}

// 小组随机分配
System.out.println("一组:" + oneTeam + "组长默认:" + oneTeam.get(1));
System.out.println("二组:" + twoTeam + "组长默认:" + twoTeam.get(3));
System.out.println("三组:" + threeTeam + "组长默认:" + threeTeam.get(3));
System.out.println("四组:" + fourTeam + "组长默认:" + fourTeam.get(2));
System.out.println("五组:" + fiveTeam + "组长默认:" + fiveTeam.get(2));
System.out.println("六组:" + sixTeam + "组长默认:" + sixTeam.get(1));
System.out.println("七组:" + sevenTeam + "组长默认:" + sevenTeam.get(3));
System.out.println("八组:" + eightTeam + "组长默认:" + eightTeam.get(3));
System.out.println("九组:" + one + "组长默认:" + one);

}

}

回首间---我错过了那片星海
原文地址:https://www.cnblogs.com/Vowzhou/p/10139193.html