i want to make a type writer exercise program.
So the program outputs to the consol a letter and the user has to type that letter in.
Thats in a loop:
import java.util.Scanner;
public class Main {
public static void main(String[] args){
int start=33;//character '!' in the ascii table
int end=126;//character '~' in the ascii table
Scanner scanner=new Scanner(System.in);
do{
int random=(int)(Math.random()*256);
while(!(random>start&&random<end)){
random=(int)(Math.random()*256);// generate a int between '!' and '!'
}
System.out.println((char)random);//print random character to the console
while(scanner.hasNext()){//this loop read the next character that i type in
String x=scanner.next();//my character that i type
String xx=Character.toString((char)random);
if(x.equals(xx)){//tries to match my input to the random character
//THIS IS WHERE IT ALL GOES WRONG, IN THE IF STATEMENT ABOVE. WHEN WHERE SUPPOSE TO BE TRUE, RETURN False
System.out.println("they are equal");
break;
}
System.out.println("WRONG");
}
}while(true);
}
}
please help.
Thank you for your kind concern.
jenia