# Integrating a StopWatch?

• September 4th, 2011, 11:12 PM
Staticity
Integrating a StopWatch?
Code :

```import java.util.Scanner;   public class main {   public static void main(String args[]){   Scanner scan = new Scanner(System.in);   System.out.println("This program is built to generate 2 digit multiplication"); System.out.println("The numbers can range from 10-99"); System.out.println("Enter the number of equations to work on below:");     int amount = scan.nextInt(); int a = 0; int correct = 0; int wrong = 0; int score = 0;   while(a < amount){ int x = 10 + (int)(Math.random()*89); int y = 10 + (int)(Math.random()*89); int z = x * y;   System.out.println(x + "x " + y);   int answer = scan.nextInt(); if(answer == z){ System.out.println("Correct!"); correct++; score += 5; } else{ System.out.println("Wrong!"); wrong++; score -= 9; } amount--; } System.out.println("\nSTATISTICS:"); System.out.println("Correct: " + correct); System.out.println("Wrong: " + wrong); System.out.println("Score: " + score); } }```

How could I create a Stopwatch that begins once the user enters the number of equations they would like to use, then have that stopwatch end once the final question is answered. Then finally be able to print out the amount of time the stopwatch was running.
• September 4th, 2011, 11:50 PM
Junky
Re: Integrating a StopWatch?
Have a look at the System class.
• September 4th, 2011, 11:55 PM
Staticity
Re: Integrating a StopWatch?
Found an easy method of doing it. Using System.currentTimeMillis();... Make two double variables to record the time. Subtract them and divide by 1000 to get the time. Thanks Junky for replying quickly.
• September 5th, 2011, 12:24 AM
Junky
Re: Integrating a StopWatch?
Exactly. You're welcome.