@@ -39,51 +39,51 @@ public static String[] createStringArray(int n){
3939 return array ;
4040 }
4141 public static void insertionSortIntTest (int numberOfRuns , int [] array ) {
42- int time = 0 ;
42+ double time = 0 ;
4343 for (int i = 0 ; i < numberOfRuns ; i ++) {
4444 final long start = System .nanoTime ();
4545 SortingAlgorithms .insertionSort (array );
4646 final long end = System .nanoTime ();
47- time += ((end - start ) / 1000000 );
47+ time += ((end - start ) / 1000000000.0 );
4848
4949 }
50- System .out .println ("Time for Int insertion: " + time /numberOfRuns );
50+ System .out .printf ("Time for int insertionSort: %.3f \n " , time /numberOfRuns );
5151 System .out .println ("Length of sorted array: " +array .length );
5252 }
5353 public static void mergeSortIntTest (int numberOfRuns , int [] array ){
54- int time = 0 ;
54+ double time = 0 ;
5555 for (int i = 0 ; i < numberOfRuns ; i ++) {
5656 final long start = System .nanoTime ();
5757 SortingAlgorithms .mergeSort (array );
5858 final long end = System .nanoTime ();
59- time += ((end - start ) / 1000000 );
59+ time += ((end - start ) / 1000000000.0 );
6060
6161 }
62- System .out .println ("Time for Int mergeSort: " + time /numberOfRuns );
62+ System .out .printf ("Time for int mergeSort: %.3f \n " , time /numberOfRuns );
6363 System .out .println ("Length of sorted array: " +array .length );
6464 }
6565 public static void insertionSortStringTest (int numberOfRuns , String [] array ) {
66- int time = 0 ;
66+ double time = 0 ;
6767 for (int i = 0 ; i < numberOfRuns ; i ++) {
6868 final long start = System .nanoTime ();
6969 SortingAlgorithms .insertionSort (array );
7070 final long end = System .nanoTime ();
71- time += ((end - start ) / 1000000 );
71+ time += ((end - start ) / 1000000000.0 );
7272
7373 }
74- System .out .println ("Time for String insertion: " + time /numberOfRuns );
74+ System .out .printf ("Time for String insertionSort: %.3f \n " , time /numberOfRuns );
7575 System .out .println ("Length of sorted array: " +array .length );
7676 }
7777 public static void mergeSortStringTest (int numberOfRuns , String [] array ){
78- int time = 0 ;
78+ double time = 0 ;
7979 for (int i = 0 ; i < numberOfRuns ; i ++) {
8080 final long start = System .nanoTime ();
8181 SortingAlgorithms .mergeSort (array );
8282 final long end = System .nanoTime ();
83- time += ((end - start ) / 1000000 );
83+ time += ((end - start ) / 1000000000.0 );
8484
8585 }
86- System .out .println ("Time for String mergeSort: " + time /numberOfRuns );
86+ System .out .printf ("Time for String mergeSort: %.3f \n " , time /numberOfRuns );
8787 System .out .println ("Length of sorted array: " +array .length );
8888 }
8989
0 commit comments