How to make a comparison between between random string and user input
807601Mar 27 2008 — edited Apr 1 2008Hi all,
Basically, my program will generate a random string using the method below,
Random rand = new Random();
int num1 = rand.nextInt(10);
int num2 = rand.nextInt(10);
int num3 = rand.nextInt(10);
char myChar1 = (char) ('A' + num1);
char myChar2 = (char) ('A' + num2);
char myChar3 = (char) ('A' + num3);
System.out.println("The random string is: " myChar1 myChar2 + myChar3);
The user will then have to guess what the string is and depending on how close the user is generate a W for no characters right, one or more O's for the correct character but in the wrong position and C's for both correct character and corect position.
Can I have something like,
if (randomstring = guess)
System.out.println("Correct");
else....
System.out.println("Your clue is: " ????)
Any suggestions?