I have been teaching myself java for fun. I found a site that gives assignments so I have been trying to teach myself by completing the programs assigned by the site. This assignment asked that I write a program asking the user to guess a random number. Anyways, this is like my 3rd day of teaching myself this stuff so I am basically feeling it out as I go. Can anybody tell me how to fix this? Or, perhaps more importantly, why this doesn't work? Any help would be appreciated.
Thanks!!!
The errors the program is giving me are all in the underlined line. They are:
-Syntax error on token 'while' delete this token.
-Syntax error on token 'boolean' delete
Things I have tried:
-I tried defining the booleans outside of the while loop.
-I tried writing in public static void main whatever (I don't fully understand what that code does yet but it semeed to impact the way the boolean instances interacted.)
Here is the code:
import java.io.*; public class pickanumber { int x = (int) ((Math.random()*10)+1) while [boolean rightguess1 = false]; { try { Reader instream = null; BufferedReader userguess = new BufferedReader (instream); System.out.println("Pick a whole number between 1 and 10"); String usguess = userguess.readLine(); int uguess1 = Integer.parseInt(usguess); if (!(uguess1==x)) { System.out.println("Try again"); boolean rightguess1 = false; } else { boolean rightguess1 = true; }} catch (IOException err) { System.out.println("Only whole numbers please"); } System.out.println("Nice job. The number was " + x); } }