I was trying out the stopwatch class in http://algs4.cs.princeton.edu/14analysis/Stopwatch.java.html . I'm using Eclipse, and here are the things I've done-
Here's the code -
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n = Integer.parseInt(args[0]);
// sum of square roots of integers from 1 to n using Math.sqrt(x).
Stopwatch timer1 = new Stopwatch();
double sum1 = 0.0;
for (int i = 1; i <= n; i++) {
sum1 += Math.sqrt(i);
}
double time1 = timer1.elapsedTime();
StdOut.printf("%e (%.2f seconds)\n", sum1, time1);
// sum of square roots of integers from 1 to n using Math.pow(x, 0.5).
Stopwatch timer2 = new Stopwatch();
double sum2 = 0.0;
for (int i = 1; i <= n; i++) {
sum2 += Math.pow(i, 0.5);
}
double time2 = timer2.elapsedTime();
StdOut.printf("%e (%.2f seconds)\n", sum2, time2);
}
}
I've added external JAR stdlib to the Java buildpath
However, when I run it, I still get the error-
Could someone please help me out and tell me what I'm doing wrong?