首页 > 代码库 > HW7.18

HW7.18

技术分享

 

 1 public class Solution 2 { 3     public static void main(String[] args) 4     { 5         int[][] m = {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}}; 6  7         shuffle(m); 8  9         for(int i = 0; i < m.length; i++)10         {11             for(int j = 0; j < m[0].length; j++)12                 System.out.print(m[i][j] + " ");13             System.out.println();14         }15     }16 17     public static void shuffle(int[][] array)18     {19         for(int i = 0; i < array.length; i++)20         {21             int randomLocation = (int)(Math.random() * array.length);22             int[] temp = new int[array[0].length];23             for(int j = 0; j < array[0].length; j++)24             {25                 temp[j] = array[i][j];26                 array[i][j] = array[randomLocation][j];27                 array[randomLocation][j] = temp[j];28             }29         }30     }31 }

 

HW7.18