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 ");}}}