Find the largest element and the smallest element in the following array, a[][]={{3,2,6},{6,8,2,10},{5},{12,3,23}}

Source: Internet
Author: User

 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}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.