Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: ; expected error

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ; expected error

    I'm getting the following error when trying to compile my code: "java:38:error: ; expected"

    I checked the line of the error referenced and I do have an ;

     
    import java.util.Random;
    import java.io.*;
     
    public class DealorNoDeal {
     
    	public static void main (String[] args)	{
     
    		System.out.println( "Welcome to Deal or No Deal Game!" );
     
    		System.out.println( "In this game, there are 10 cases containing 	
     
    		various amounts of money. Three of those cases contain no money. Of 
     
    		the seven cases that do contain money, they contain the following 	
     
    		amounts: $1, $10, $100, $1,000, $10,000, $100,000 and $1,000,000");
     
    		System.out.println("You will be asked to select a case to open. 	
     
    		You'll have the opportunity to open up to 3 cases. But, if you 		
     
    		decide you like the amount before the third case is opened, you can 
     
    		stop the game at that point. But, if you use all three tries, 		
     
    		you'll have to take the amount received on your third try.");
     
    		System.out.println("Let's start the game!");
     
    //Setup looping mechanism to ensure user can only guess a maximum of three times.
     
     
    	for (numofGuesses=0;numofGuesses < 3;) {
    		GameHelper helper = new GameHelper();
    		helper.getUserInput("Enter a case number between 0 and 9: ");
    		System.out.println("The case you selected contains: " + 		
     
    		val(arr[position]));
     
     
    		helper.getUserYN("Deal or No Deal? Y or N");
    			if (line.equalsIgnoreCase("N"))	{
    				numofGuesses++; //If user answers "n" continue loop
    			}
     
    			else 	{
     
    			break; //If user answers "y" terminate the loop
     
    			}
    	}
     
    	//Print the amount user has won. Game over at this point.
    	System println("The amount you've won is:" + val(arr[position]);
     
     }
     
    }
     
    public class RandomArr {
     
        private static Random rand = new Random ();
     
        // instance variable to hold dollar amounts inside an array
        private int [] arr = { 0,0,0,1,10,100,1000,10000,100000,1000000};
     
        // setter method that randomly assigns amounts to positions inside array
        public RandomArr(){
            int tempVal;
            int randPos;
     
            for ( int i=0; i<10; i++ ) {
                for ( int j=0; i<arr.length; i++ ) {
                    randPos = rand.nextInt ( arr.length );
                    tempVal = arr[j];
                    arr[j] = arr[randPos];
                    arr[randPos] = tempVal;
                }
            }
    	}
     
    	// getter for value of a certian position inside the array
    		public int getValue(int position){
    		return arr[position];
    	}
    	}
     
     
     
    public class GameHelper {
     
     
    	public String getUserInput(String prompt) {
     
    		String inputLine = null;
    		System.out.print(prompt + " ");
     
    		try {
    			BufferedReader is = new BufferedReader(new 			
     
    	InputStreamReader(System.in));
    			inputLine = is.readLine();
     
    			if (inputLine.length() == 0) return null;
    		}
     
    		catch (IOException e) {
    			System.out.println("Exception: " + e);
    		}
     
    		return inputLine;
    	}
     
     
    	// getter method that converts String value received from the user into an 	
     
    	//integer
    	public int getUserInt(String prompt){
     
    		String line = getUserInput(prompt);
    		int val = Integer.parseInt(line);
     
    		return val;
     
    	}
     
    	// getter boolean method that returned true if the user pressed Y and false 
     
    	//otherwise
    	// this is for the step when the user is asked Deal or No Deal question
    	public boolean getUserYN(String prompt){
    		String line = getUserInput(prompt);
     
    		return(line.equalsIgnoreCase("Y"));
    	}	
     
        }


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,622
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: ; expected error

    We have no idea what line 38 is.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ; expected error

    I added comments codes for the referenced line:

     
     
    		//Display the amount contained in the case selected by user
    		System.out.println("The case you selected contains: " + val(arr[position]));

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,622
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: ; expected error

    Are you sure thats the only error you are getting? As far as I can tell, the scope of that line of code doesn't have access to the val, arr, or position variables.

    --- Update ---

    Actually, in your code, arr and position are variables and val is a method. Still, that line of code shouldn't have scope access to arr or position, and a val() method doesn't appear to even exist.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ; expected error

    I just tried to compile again. That's the only error received.

  6. #6
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,622
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: ; expected error

    Is that the exact formatting of your code? With the first few printlns being split up like that? If so, that would be your problem. String's don't wrap around lines. If you want to declare a String on multiple lines, you have to concatenate.

    Example:
    //This should be a compile error:
    String var = "This is
    	      a String";
     
    //This should compile properly:
    String var = "This is " +
    	     "a String";
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  7. #7
    Junior Member
    Join Date
    Sep 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ; expected error

    I modified the println statements

     
    //Display the amount contained in the case selected by user
    		//Display the amount contained in the case selected by user
    		System.out.println("The case you selected contains: ");					 System.out.println(val(arr[position]));


    --- Update ---

    Disregard that previous post.

     
    //Display the amount contained in the case by user
    System.out.println(The case you selected contains: " +);
    System.out.println(val(arr[position]));

    Same error

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,784
    My Mood
    Mellow
    Thanks
    175
    Thanked 625 Times in 612 Posts

    Default Re: ; expected error

    The String broken across multiple lines is done improperly. Here's an example of how the first one should be done:
    		System.out.println( "In this game, there are 10 cases containing " +
    				"various amounts of money. Three of those cases contain no" +
    				" money. Of the seven cases that do contain money, " +
    				"they contain the following amounts: $1, $10, $100, " +
    				"$1,000, $10,000, $100,000 and $1,000,000");

  9. #9
    Junior Member
    Join Date
    Sep 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ; expected error

    Still getting the error. I made the changes on the lines you pointed out, eventhough they weren't referenced in any of the errors. Still getting "java:40:error: ; expected". I concatenated and it's all on one line:

     
    //Print the amount user has won. Game over at this point.
    	System println("The amount you've won is:" + val(arr[position]));

    Here's the entire code revised:

     
    import java.util.Random;
    import java.io.*;
     
    public class DealorNoDeal {
     
    	public static void main (String[] args)	{
     
    		System.out.println( "Welcome to Deal or No Deal Game!" );
     
    		System.out.println( "In this game, there are 10 cases containing" + 
     
    		"various amounts of money. Three of those cases contain no money."+ 
     
    		"Of the seven cases that do contain money, they contain the" + 		
     
    		"following amounts: $1, $10, $100, $1,000, $10,000, $100,000" +		
     
    				"and $1,000,000");
     
    		System.out.println("You will be asked to select a case to open."+ 	
     
    		"You'll have the opportunity to open up to 3 cases. But, if you" + 	
     
    		"decide you like the amount before the third case is opened, you"+ 	
     
    		"can stop the game at that point. But, if you use all three" + 		
     
    		"tries,you'll have to take the amount received on your" +		
     
    		"third try.");
     
    		System.out.println("Let's start the game!");
     
    //Setup looping mechanism to ensure user can only guess a maximum of three times.
     
     
    	for (numofGuesses=0;numofGuesses < 3;) {
    		GameHelper helper = new GameHelper();
    		helper.getUserInput("Enter a case number between 0 and 9: ");
     
    		//Display the amount contained in the case selected by user
    		System.out.println("The case you selected contains: " + 		
     
    		(Val(arr[position])));
     
     
    		helper.getUserYN("Deal or No Deal? Y or N");
    			if (line.equalsIgnoreCase("N"))	{
    				numofGuesses++; //If user answers "n" continue loop
    			}
     
    			else 	{
     
    			break; //If user answers "y" terminate the loop
     
    			}
    	}
     
    	//Print the amount user has won. Game over at this point.
    	System println("The amount you've won is:" + val(arr[position]));
     
     }
     
    }
     
    public class RandomArr {
     
        private static Random rand = new Random ();
     
        // instance variable to hold dollar amounts inside an array
        private int [] arr = { 0,0,0,1,10,100,1000,10000,100000,1000000};
     
        // setter method that randomly assigns amounts to positions inside array
        public RandomArr(){
            int tempVal;
            int randPos;
     
            for ( int i=0; i<10; i++ ) {
                for ( int j=0; i<arr.length; i++ ) {
                    randPos = rand.nextInt ( arr.length );
                    tempVal = arr[j];
                    arr[j] = arr[randPos];
                    arr[randPos] = tempVal;
                }
            }
    	}
     
    	// getter for value of a certian position inside the array
    		public int getValue(int position){
    		return arr[position];
    	}
    	}
     
     
     
    public class GameHelper {
     
     
    	public String getUserInput(String prompt) {
     
    		String inputLine = null;
    		System.out.print(prompt + " ");
     
    		try {
    			BufferedReader is = new BufferedReader(new 			
     
    	InputStreamReader(System.in));
    			inputLine = is.readLine();
     
    			if (inputLine.length() == 0) return null;
    		}
     
    		catch (IOException e) {
    			System.out.println("Exception: " + e);
    		}
     
    		return inputLine;
    	}
     
     
    	// getter method that converts String value received from the user into an 	
     
    	//integer
    	public int getUserInt(String prompt){
     
    		String line = getUserInput(prompt);
    		int val = Integer.parseInt(line);
     
    		return val;
     
    	}
     
    	// getter boolean method that returned true if the user pressed Y and false 
     
    	//otherwise
    	// this is for the step when the user is asked Deal or No Deal question
    	public boolean getUserYN(String prompt){
    		String line = getUserInput(prompt);
     
    		return(line.equalsIgnoreCase("Y"));
    	}	
     
        }

  10. #10
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,784
    My Mood
    Mellow
    Thanks
    175
    Thanked 625 Times in 612 Posts

    Default Re: ; expected error

    There are a number of errors, mostly syntax, some plain ol' typos, that need to be cleaned up. We shouldn't have to do that for you. If you run into errors that you can't figure out, post the exact error and the code to which it applies, both EXACTLY as they appear to you, copied and pasted.

  11. #11
    Junior Member
    Join Date
    Sep 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ; expected error

    I did post the exact error message and the line which it applies to. The exact error is: "java:40:error: ; expected"

    I have a ; there, so I'm not sure why it's flagging that code saying it's not there.

     
     
     
    	//Print the amount user has won. Game over at this point.
    	System println("The amount you've won is:" + (val(arr[position])));

  12. #12
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: ; expected error

    System println
    vs
    System.out.println

  13. #13
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ; expected error

    This line of code stands out:
     
    //Print the amount user has won. Game over at this point.
    	System println("The amount you've won is:" + val(arr[position]));

    The line above should have System.out.println() instead of System println

    //Print the amount user has won. Game over at this point.
    	System.out.println("The amount you've won is:" + val(arr[position]));

  14. #14
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,784
    My Mood
    Mellow
    Thanks
    175
    Thanked 625 Times in 612 Posts

    Default Re: ; expected error

    No, that's not the exact error. That's one line or a few words you copied from the exact error, if you're talking about a compiler error and not some red-squiggly tooltip statement from an IDE.

    Either way, the IDE or compiler is doing its best to process your code with multiple syntax errors, typos, and just plain mistakes and point you to where the problem is. Sometimes it's not exactly where the error is pointing to but a line or two before or afterwards.

    You've already been pointed to the "System println" error. You should have found that one yourself. I also see a number of variables that have been neither declared nor initialized. Those will be in a compiler error somewhere, and you haven't posted one that includes those.

Similar Threads

  1. Syntax error on tokens, interfaceheader expected instead
    By Judas in forum What's Wrong With My Code?
    Replies: 15
    Last Post: June 5th, 2013, 02:47 PM
  2. error Identifier expected?
    By chandresh in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 15th, 2012, 02:34 AM
  3. [SOLVED] MS Access Error: Too Few Parameters. Expected 2?
    By Kimiko Sakaki in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 13th, 2012, 08:31 PM
  4. '{' expected error please help
    By erdy_rezki in forum What's Wrong With My Code?
    Replies: 8
    Last Post: April 9th, 2012, 10:01 AM
  5. un-expected error
    By arvindbis in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 21st, 2011, 09:02 AM