・ Arrangement is random ・ I want to place one or more women somewhere in a horizontal row ・ If a person with bad eyesight enters, fix it in front ・ Easy-to-understand code
Get out of the shuffled list with get (). Made it look like a seat with System ~ println
・ Arrangement is random → The result changes every time with Collections.shuffle () ・ I want to place one or more women somewhere in a horizontal row → In advance, we decided where to place women and men. ・ Fixing people with bad eyesight → Remove it from the list and delete the "~ get ()" to make it the name of the person to fix.
import java.util.ArrayList;
import java.util.Collections;
public class Sekigae4 {
public static void main(String[] args) {
ArrayList<String> man = new ArrayList<String>();
man.add("Male 1");
man.add("Male 2");
man.add("Male 3");
man.add("Male 4");
man.add("Male 5");
man.add("Male 6");
man.add("Male 7");
man.add("Male 8");
man.add("Male 9");
man.add("Male 10");
man.add("Male 11");
man.add("Male 12");
ArrayList<String> woman = new ArrayList<String>();
woman.add("Female 1");
woman.add("Woman 2");
woman.add("Woman 3");
woman.add("Female 4");
woman.add("Female 5");
woman.add("Female 6");
woman.add("Female 7");
woman.add("Female 8");
Collections.shuffle(man);
Collections.shuffle(woman);
System.out.println("--After sorting--");
System.out.println(woman.get(0) + " | " + man.get(0) + " | " + man.get(1) + " | "+ man.get(2));
System.out.println(woman.get(1) + " | " + man.get(3) + " | " + man.get(4) + " | "+ woman.get(2));
System.out.println(man.get(5) + " | " + man.get(6) + " | " + man.get(7) + " | "+ woman.get(3));
System.out.println(woman.get(4) + " | " + woman.get(5) + " | " + man.get(8) + " | "+ man.get(9));
System.out.println(man.get(10) + " | " + man.get(11) + " | " + woman.get(6) + " | "+ woman.get(7));
}
}
Recommended Posts