码迷,mamicode.com
首页 > 其他好文 > 详细

HW7.16

时间:2016-09-13 13:10:21      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5868040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!