This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm trying to create a simple program that uses a text file to randomly generate a sequence of letters. Where I stuck is how to use the info in the file to choose the letters. Heres the file 10 a 50 b 100 c I roll a random number from 1-100 and then pick the letter that matches the number. I can read the file, and roll the number fine the problem is at the >>>>> marker.
How do I compare the int roll to the number in the String? Thanks this is my first post on this new board. I am completely self taught in java. It probably shows Mario [ edited to preserve formatting using the [code] and [/code] UBB tags -ds ] [ April 09, 2004: Message edited by: Dirk Schreckmann ]
use Integer.parseInt(st1.nextToken()) to convert String into number then compare it with roll.
Joined: Apr 08, 2004
Thanks that works, but now I have another problem. When it does match the numbers and sets the variable letter, it doesn't break out of the for loop. It either beeps and stops or if the if statment was successful it goes again until its false. Edited: Ok I added break out; and that works, the problem is when the if statment is false it doesn't go the next line and compare its number to the rolled number. it beeps and stops there. Should the while statment be something else? [ April 08, 2004: Message edited by: Mario Bonassin ] I think I got it, I just took away the while statement and left the rest the same and it seems to be working. Thanks [ April 08, 2004: Message edited by: Mario Bonassin ]