Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to make a comparison between between random string and user input

807601Mar 27 2008 — edited Apr 1 2008
Hi 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 29 2008
Added on Mar 27 2008
12 comments
1,114 views