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