I have a very simple program that times how long it takes to selection-sort 100000 numbers. Here's the code:
import java.util.Calendar;
import java.util.GregorianCalendar;
public class Stopwatch {
public static void main(String[] args) {
// Create a stopwatch
int howManyNumbers = 100000;
Integer[] numbers = new Integer[howManyNumbers];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = (int)(100 * Math.random());
}
System.out.println("Array created");
StopWatching watch = new StopWatching();
System.out.println("Sorting started");
for (int i = 0; i < numbers.length; i++ ) {
for (int j = i; j < numbers.length; j++) {
if (numbers[j] < numbers[i]) {
int temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
}
}
System.out.print("Finished the sort");
watch.stop();
System.out.println();
System.out.println(watch.getElapsedTime());
for (int i = 0; i < numbers.length; i++) {
System.out.print(numbers[i]);
}
}
}
This runs, prints "Array Created" and "Sorting Started" to the console, goes for a second or two, then just stops. No error or warning. Doesn't print "Finished the sort" or anything like that. It is supposed to print "Finished the sort", then the time elapsed which is returned from the watch.getElapsedTime() (object of StopWatching class, which works, has been tested in other environments).
Can anyone indicate what I'm doing wrong here?
NOTE: The return type of watch.getElapsedTime() is a Long which is the time in milliseconds calculated from when the watch is created to when the watch.stop() method is called (by utilizing the GregorianCalendar class).
P.S. I'm using eclipse IDE

StopWatchingclass.Stopwatching, or this is just a bug of eclipse