package Day4; import java.util.*; public class Test5 { public static void main(String[] args) { Map<String,Integer> map = new HashMap<>(); List<String> list = new ArrayList<>(); Collections.addAll(list,"乌拉圭","俄罗斯","西班牙","葡萄牙","法国","丹麦","克罗地亚","阿根廷","巴西","瑞士","瑞典","墨西哥","比利时","英格兰","哥伦比亚","中国"); System.out.println(list); for(int i=1;i<17;i++) { System.out.print(list.get(i-1)); if(i%4==0) System.out.println(); } List<Integer> list1 =new ArrayList<>(); Collections.shuffle(list1);//工具类shuffle用来打乱扑克牌! List<Integer> class1=new ArrayList<>(); List<Integer> class2=new ArrayList<>(); List<Integer> class3=new ArrayList<>(); List<Integer> class4=new ArrayList<>(); for (int i = 0; i < list.size(); i++) { if (i % 4 == 0) { class1.add(list1.get(i)); } else if (i % 4 == 1) { class2.add(list1.get(i)); } else if (i % 4 == 2) { class3.add(list1.get(i)); } else if (i % 4 == 3) { class4.add(list1.get(i)); } } System.out.println("甲组"+class1); System.out.println("乙组"+class2); System.out.println("丙组"+class3); System.out.println("丁组"+class4); ArrayList<String> dipai1 = new ArrayList<>(); ArrayList<String> player1 = new ArrayList<>(); ArrayList<String> player2 = new ArrayList<>(); ArrayList<String> player3 = new ArrayList<>(); for (Integer integer: class1) { dipai1.add(list.get(integer)); } System.out.println(dipai1); for (Integer integer:class2) { player1.add(list.get(integer)); } System.out.println(player1); for (Integer integer: class3) { player2.add(list.get(integer)); } System.out.println(player2); for (Integer integer:class4) { player3.add(list.get(integer)); } System.out.println(player3); } }
java斗地主发牌编写
最新推荐文章于 2020-07-07 17:03:00 发布