Please provide the program. The function is to get the running duration of "a piece of program code" and provide the program code

Source: Internet
Author: User

Please provide the program. The function is to get the running duration of "a piece of program code" and provide the program code

One day I saw a few java questions, so I wrote a little bit. I just went straight to the code.

3. Known int-type array arr [t],

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

② The maximum and minimum values of the output array are min.

③ Sort the array by Bubble sorting and print the sorted array.

4. Provide a program. The function is to obtain the running duration of a piece of program code. Requirements:

① The program framework is defined in the parent class.

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

③ "A piece of program code": print a graph composed of "*", as shown in figure 1.

Figure 1

Question 3:

Public class testArr {public static void main (String [] arg) {int [] arr = {,}; System. out. println ("print out array:"); System. out. print ("["); for (int I = 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 int getMax (int [] arr) {int max = Integer. MIN_VALUE; for (int I = 0; I <arr. length; I ++) {if (arr [I]> max) max = arr [I];} return max;} public static int getMin (int [] arr) {int min = Integer. MAX_VALUE; for (int I = 0; I <arr. length; I ++) {if (arr [I] <min) min = arr [I];} return min;} public static int arrSort (int [] arr) {for (int I = arr. length-1; I> = 0; I --) {for (int j = 0; j <I; j ++) {if (arr [j]> arr [j + 1]) {int temp = arr [j]; arr [j] = arr [j + 1]; arr [j + 1] = temp ;}} System. out. println ("Bubble sorting result:"); System. out. print ("["); for (int I = 0; I <arr. length; I ++) {System. out. print (arr [I] + ",");} System. out. print ("]"); return 0 ;}}
Running result:

Question 4:

Public class Diamond {public static void main (String [] args) {long startTime = System. currentTimeMillis (); oneCode (); long endTime = System. currentTimeMillis (); System. out. print ("\ n" + "program running time:" + (endTime-startTime) + "ms");} public static void oneCode () {for (int I = 1; I <5; I ++) {for (int j = 1; j <I + 4; j ++) {for (int t = 0; t <I; t ++) {if (j = (5-i + 2 * t) {System. out. print ("*") ;}} System. out. print ("");} System. out. print ("\ n ");}}}

 

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.