/************************************************************************* * Compilation: javac Stopwatch.java * * *************************************************************************/ public class Stopwatch { private long start; public Stopwatch() { start = System.currentTimeMillis(); } // start the stopwatch public double elapsedTime() { long current = System.currentTimeMillis(); return (current - start) / 1000.0; } // test client public static void main(String[] args) { int N = Integer.parseInt(args[0]); Stopwatch timer = new Stopwatch(); int sum = 0; for (int i = 0; i < N; i++) sum += i*i*i; System.out.println(sum); System.out.println("elapsed time = " + timer.elapsedTime()); } }