Question: Intro to Java Time Controlled Repetition and Char Values Can someone fix my jGrasp Java code? I want it to simply ask for one character
Intro to Java
Time Controlled Repetition and Char Values
Can someone fix my jGrasp Java code? I want it to simply ask for one character each time but instead, it's asking for the same character twice when prompted. And please don't do anything that wouldn't be done in an introductory Java class. import java.util.Scanner; import java.util.Random;
public class TypingPractice { public static void main(String[] args) { Scanner input = new Scanner(System.in); Random rNums = new Random(); char z; int correct = 0, incorrect = 0; int count = 0; long startTime, endTime; long timeElapsed = 0; char c; System.out.println("Welcome to the typing practice! When you see a letter displayed on the screen, type the same letter on your keyboard. Let's see how many you can score in 1 minute!");
startTime = System.currentTimeMillis(); while (timeElapsed <= 60) { c = (char)('a' + rNums.nextInt(26)); System.out.print( " Please type: " +c); System.out.println((char)('a' + rNums.nextInt(26))); z = input.next().charAt(0); if (z == c) { correct++; } else { incorrect++; timeElapsed++; } } endTime = System.currentTimeMillis(); timeElapsed = endTime - startTime; System.out.printf("Congratulation! Within 1 minute, you typed %d letters. You are %d correct in this practice. ", count, correct); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
