packagecom.homework.zw;//the idea of solving a problem: iterate through all the elements of a two-dimensional array and form a new one-dimensional array with these Elements. The bubble sort is then used to find the largest and smallest elements of a one-dimensional array. public classwork2{ public Static voidmain (string[] Args) {int[] a ={{3,2,6},{6,8,2,10},{5},{12,3,23}}; int[] b=New int[11]; intC=0,e=0; for(intI =0;i<a.length;i++) { for(intJ =0;j<a[i].length;j++) { for(intK =e;k<11;k++) {b[k]=a[i][j]; E++; break; } } }//the above is the traversal of the two-dimensional array and the synthesis of a new one-dimensional array of all the elements of the two-dimensional array for(ints=0;s<10;s++) { for(intT =s+1;t<11;t++) { if(b[s]<b[t]) {c=b[t]; b[t]=b[s]; b[s]=c; } } }//the above uses the bubble sort to find the largest element and the smallest elementSystem.out.println ("the largest element in the array is:" +b[0]); System.out.println ("the smallest element in the array is:" +b[10]); }}
Find the largest element and the smallest element in the following array, a[][]={{3,2,6},{6,8,2,10},{5},{12,3,23}}