I'm programming a project which calculates the time that it takes the user to write the answer. So I will display a question and you'll answer it. After that, I will display the time it takes for you to solve it.
But the reaction time is not working when I put the variables inside my while loop.
Here is the code:
long startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
long reactionTime = endTime - startTime;
//Q1
System.out.println("Q1");
while (true) {
System.out.println("What is 1+1: ");
int ans = scanner.nextInt();
if (ans == 2) {
System.out.println("Correct");
System.out.println(reactionTime + "ms");
break;
} else {
System.out.println("incorrect please try again");
}
}