定义了一个扑克牌的一维数组,现在已经打乱了,怎么将打乱后的数据用二维数组的形式输出6X9

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;
		}
	}
}


Saber专属
浏览 1182回答 2
2回答

望远

for(int i = 0 ;i<poke.length;i++) {   System.out.print("  "+poke[i]);   if((i+1)%9==0)   {   System.out.println();   } }

望远

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();       }这样就行了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java