Please give the program, function to get "a piece of program code" run length

Source: Internet
Author: User

One day I saw a few Java topics, I wrote a bit, nonsense less, directly on the code

3. Known int array arr[t],

Please: ① print the array. The output format is: [Arr1,arr2,arr3,...].

② the maximum value of the output array, max and Min.

③ uses the bubbling sort to sort the array and prints the sorted arrays.

4. Please give the program, function to get "a piece of program code" run time. Requirements:

The ① program framework is defined in the parent class.

② "A piece of program code" is given in the subclass and overrides the corresponding method in the parent class.

③ "Part of the program code" is: Print a "*" composed of graphics, see Figure 1.

Figure 1

Question three:

 Public classTestarr { Public Static voidMain (string[] arg) {int[] arr = {23,12,3,45,25,46,75,15,12,52}; System.out.println ("Print Array:"); System.out.print ("[");  for(inti=0;i<arr.length;i++) {System.out.print (Arr[i]+", "); } System.out.print ("]"); System.out.println ("\ n" + "Maximum value:" +Getmax (arr)); System.out.println ("Minimum value:" +getmin (arr));    Arrsort (arr); }     Public Static intGetmax (int[] arr) {          intMax =Integer.min_value;  for(inti = 0; i < arr.length; i++) {              if(Arr[i] >max) Max=Arr[i]; }          returnMax; }       Public Static intGetmin (int[] arr) {          intMin =Integer.max_value;  for(inti = 0; i < arr.length; i++) {              if(Arr[i] <min) min=Arr[i]; }          returnmin; }       Public Static intArrsort (int[] arr) {                   for(inti=arr.length-1;i>=0;i--){             for(intj=0;j<i;j++){                if(arr[j]>arr[j+1]){                    inttemp =Arr[j]; ARR[J]= Arr[j+1]; Arr[j+1] =temp; }}} System.out.println ("Bubble sort thick Result:"); System.out.print ("[");  for(inti=0;i<arr.length;i++) {System.out.print (Arr[i]+", "); } System.out.print ("]"); return0; }  }
Operation Result:

Question Fourth:

 Public classdiamond{ Public Static voidMain (string[] args) {LongStarttime=System.currenttimemillis ();   Onecode (); LongEndtime=System.currenttimemillis (); System.out.print ("\ n" + "program Run Time:" + (Endtime-starttime) + "MS"); }  Public Static voidOnecode () { for(inti=1;i<5;i++){     for(intj=1;j<i+4;j++){         for(intt=0;t<i;t++){            if(j== (5-i+2*t)) {System.out.print ("*"); }} System.out.print (" "); } System.out.print ("\ n"); }}}

Please give the program, function to get "a piece of program code" run length

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.