- class ForForDemo
- {
- public static void main(String[] args)
- {
- int [] [] arr={{9,2,3,6},{12,2,34,23,1},{2,3,12,34,6},{2,4,13,12}};
- printArray(arr);
- bubbleSort(arr);
- printArray(arr);
-
- int sum=getArray(arr);
- System.out.println("sum="+sum);
- }
- public static int getArray(int[] []arr)
- {
- int sum=0;
- for (int x=0;x<arr.length ;x++ )
- {
- for (int y=0 ;y<arr[x].length ;y++ )
- {
- sum =sum+arr[x][y];
- }
- }
- return sum;
- }
- public static int bubbleSort(int [][]arr)
- {
- for (int x=0;x<arr.length ;x++ )
- {
- for (int y=0;y<arr[x].length-1 ;y++ )
- {
- for (int z=y+1;z<arr[x].length-y-1 ;z++ )
- {
- if (arr[y][z]>arr[y][z+1])
- {
- int temp=arr[y][z];
- arr[y][z]=arr[y][z+1];
- arr[y][z+1]=temp;
- }
- }
-
-
- }
- }
- return -1;
- }
- public static int printArray(int [][]arr)
-
- {
-
- for (int x=0; x<arr.length;x++ )
- {
- System.out.print("[");
- for (int y=0;y<arr[x].length ;y++ )
- {
- if (y!=arr[x].length-1)
- {
- System.out.print(arr[x][y]+",");
- }
- else System.out.println(arr[x][y]+"]");
- }
- }
- return -1;
- }
- }
复制代码 二维数组,多维数组怎么排序啊。最好写详细的过程 |