import java.util.Random; public class Homewrok1112_2m { public static void main(String[] args) { // TODO Auto-generated method stub String[] poke = new String[] {"红A","红2","红3","红4","红5","红6","红7","红8","红9","红10","红J","红Q","红K", "黑A","黑2","黑3","黑4","黑5","黑6","黑7","黑8","黑9","黑10","黑J","黑Q","黑K", "梅A","梅2","梅3","梅4","梅5","梅6","梅7","梅8","梅9","梅10","梅J","梅Q","梅K", "方A","方2","方3","方4","方5","方6","方7","方8","方9","方10","方J","方Q","方K", "大王","小王"}; /* List<String> list = Arrays.asList(poke); Collections.shuffle(list); for (String str : list){ System.out.print(str); */ shuffer(poke); for(int i = 0 ;i<poke.length;i++) { System.out.println(poke[i]); } } public static void shuffer(String[] poke){ Random random = new Random(); int length = poke.length; for (int i = 0; i < length; i++) { int index = random.nextInt(length); //与随机的位置交换数据 String temp = poke[i]; poke[i] = poke[index]; poke[index] = temp; } } }
望远
望远
相关分类