Yesterday I was screwing around with Java, and I wrote this application.
public class MaxInt {
public static void main(String[] args){
long startTime = System.currentTimeMillis();
long endTime;
for(int i = 0; i < 2147483647; i++){
}
endTime = System.currentTimeMillis();
long timeneeded = startTime - endTime;
System.out.println("It took " + timeneeded + " milliseconds to count to 2,147,483,646.");
}
}
Strangely, however, timeneeded is equal to -3 after the loop has completed, which doesn't make any sense to me at all. I was just curious as to why, and how, this program could generate time.