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;
}
}
}
2 回答
已采纳
望远
TA贡献1017条经验 获得超1032个赞
for(int i = 0 ;i<poke.length;i++) { System.out.print(" "+poke[i]); if((i+1)%9==0) { System.out.println(); } }
望远
TA贡献1017条经验 获得超1032个赞
String[][]arr=new String[6][9]; for(int i=0,j=0;j<arr.length;j++){ for(int k=0;k<arr[j].length;k++){ arr[j][k]=poke[i++]; } } for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ System.out.print(" "+arr[i][j]); } System.out.println(); }
这样就行了。
添加回答
举报
0/150
提交
取消