fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. // Use this editor to write, compile and run your Java code online
  4. import java.util.Random;
  5. class Main
  6. {
  7. public static void main(int[] arr) {
  8.  
  9.  
  10.  
  11.  
  12. /**
  13.  *
  14.  * @author Mukul
  15.  */
  16.  
  17. int n = arr.length;
  18. int temp;
  19. for(int i=0; i < n; i++){
  20. for(int j=1; j < (n-i); j++){
  21. if(arr[j-1] > arr[j]){
  22. //swap elements
  23. temp = arr[j-1];
  24. arr[j-1] = arr[j];
  25. arr[j] = temp;
  26. }
  27.  
  28. }
  29. }
  30.  
  31. }
  32. public static void main(String[] args) { //int n;
  33. // Scanner sc=new Scanner(System.in);
  34. // System.out.print("Enter the number of elements you want to store: ");
  35. // n=sc.nextInt();
  36.  
  37. int[] arr = new int[10000];
  38. Random r= new Random(System.currentTimeMillis());
  39. double[]exeT =new double[30];
  40.  
  41. //System.out.println("Enter the elements of the array: ");
  42. for(int k=0;k<30;k++){
  43. for(int i=0; i<arr.length; i++) {
  44. arr[i]=r.nextInt(1000);
  45.  
  46. }
  47.  
  48. double startT = System.currentTimeMillis();
  49. main(arr);//sorting array elements using bubble sort
  50. double endT = System.currentTimeMillis();
  51. exeT[k]= endT - startT;}
  52.  
  53. System.out.println("Array of Execution Time");
  54. for(int i=0; i < 30; i++){
  55.  
  56. System.out.println(exeT[i] + " ");
  57. }
  58. }
  59. }
  60.  
  61.  
Success #stdin #stdout 3.75s 56148KB
stdin
Standard input is empty
stdout
Array of Execution Time
152.0 
142.0 
117.0 
125.0 
112.0 
118.0 
120.0 
124.0 
110.0 
122.0 
121.0 
121.0 
109.0 
124.0 
123.0 
116.0 
109.0 
124.0 
119.0 
120.0 
108.0 
126.0 
123.0 
118.0 
105.0 
126.0 
124.0 
117.0 
111.0 
122.0