public class StopWatch { private long startTime = 0; private long stopTime = 0; private boolean running = false; public void start() { this.startTime = System.currentTimeMillis(); this.running = true; } public void stop() { this.stopTime = System.currentTimeMillis(); this.running = false; } public long getElapsedTime() { long elapsed; if (running) { elapsed = (System.currentTimeMillis() - startTime); } else { elapsed = (stopTime - startTime); } return elapsed; } public long getElapsedTimeSecs() { long elapsed; if (running) { elapsed = ((System.currentTimeMillis() - startTime) / 1000); } else { elapsed = ((stopTime - startTime) / 1000); } return elapsed; } public static void main(String[] args) { StopWatch s = new StopWatch(); s.start(); // code i want to time goes here // System.out.println("fsck teh hello world programs"); // // // need to figure out how to register keystrokes // within the program: // // push space bar, timer starts // solve cube // push space bar, timer stops // displays my time in minutes:seconds:milliseconds // ------------------------------------------------------- s.stop(); System.out.println("elapsed time in milliseconds: " + s.getElapsedTime()); }}