This is my first post here in regards to a programming problem (I'm excited!). I have been working through Sam's Teach Yourself Java and have came across a workshop in the book that tests how fast your system is operating. This code is in the book, I have typed it out code for code, and cannot get it to run properly in NetBeans. When I ran it the first time I received '0 loops in one minute' now for some reason (nothing has changed) the program does not stop running.
If anyone can help me out with whats wrong that would be great, I'm actually learning it and not just looking for an answer so I really need to know whats going on in the code that is causing this issue.
import java.util.*;
class Benchmark {
public static void main(String[] args) {
Calendar start = Calendar.getInstance();
int startMinute = start.get(Calendar.MINUTE);
int startSecond = start.get(Calendar.SECOND);
start.roll(Calendar.MINUTE, true);
int nextMinute = start.get(Calendar.MINUTE);
int nextSecond = start.get(Calendar.SECOND);
int index = 0;
while (true) {
double x = Math.sqrt(index);
GregorianCalendar now = new GregorianCalendar();
if (now.get(Calendar.MINUTE) >= nextSecond) {
if (now.get(Calendar.SECOND) >= nextSecond) {
break;
}
}
index++;
}
System.out.println(index + " loops in one minute.");
}
}
Thanks for all of your time and for stopping in to take a look.


Sign In
Create Account


Twitter
Back to top









