首页 > 代码库 > HW7.16

HW7.16

技术分享

 

 1 import java.util.Arrays; 2  3 public class Solution 4 { 5     public static void main(String[] args) 6     { 7         int row = (int)(Math.random() * 10); 8         int column = (int)(Math.random() * 10); 9         int[][] array = new int[row][column];10 11         for(int i = 0; i < row; i++)12         {13             for(int j = 0; j < column; j++)14             {15                 array[i][j] = (int)(Math.random() * 100);16                 System.out.print(array[i][j] + " ");17             }18             System.out.println();19         }20 21         sort(array);22 23         for(int i = 0; i < row; i++)24         {25             for(int j = 0; j < column; j++)26                 System.out.print(array[i][j] + " ");27             System.out.println();28         }29     }30 31     public static void sort(int[][] m)32     {33         for(int[] i: m)34             Arrays.sort(i);35 36         int temp;37         for(int i = 0; i < m.length; i++)38             for(int j = i; j < m.length; j++)39                 if(m[j][0] < m[i][0])40                 {41                     for(int k = 0; k < m[0].length; k++)42                     {43                         temp = m[j][k];44                         m[j][k] = m[i][k];45                         m[i][k] = temp;46                     }47                 }48     }49 }

 

HW7.16