Results 1 to 6 of 6
  1. #1
    basla is offline Member
    Join Date
    Mar 2011
    Posts
    13
    Rep Power
    0

    Default Do you know why I'm getting "cannot find symbol" error?

    Anybody have any ideas on what I'm doing wrong here?

    I made a program that prints out a square of asterisks. Now I need to modify it so the square is printed using whatever character a user types in when prompted. My assignment specifies that I need to use the statement "char fill = input.next().charAt(0)" to read the character from the user. I must have used that statement incorrectly though, because jgrasp keeps highlighting it and saying "cannot find symbol."

    Can anyone help?

    Java Code:
    import java.util.Scanner;
    public class parameterAssignment
    {
    	
    	//Main method begins execution of Java program
    	public static void main( String[] args )
    	{
    		//We will be using information typed in by keyboard
    		Scanner keyboard = new Scanner (System.in);
    	
    		//Ask user for input
    		System.out.print(" We're going to make a square.\n How many units wide would you like it to be? ");
    		int side = keyboard.nextInt();
    		System.out.print(" We'll make the square out of a character of your choosing. \nPlease enter any one character on the keyboard. ");
    		char fill = input.next().charAt( 0 );
    		squareOfAsterisks(side, fill);
    	}//end main
    	
    	
    	public static void squareOfAsterisks(int side, char fill)
    	{
    		for (int i=1;i<=side;i++)/*declare and initialze control 
    		variable; set loop continuation condition; increment control 
    		variable by 1*/ 
    
    		{ 
    		for (int j=1;j<=side;j++)/*declare and initialze control 
    		variable; set loop continuation condition; increment control 
    		variable by 1*/ 
    
    		{
    		System.out.print(fill);
    		}
    		System.out.println();
    		}
    	}
    			
    	
    }//end class squareOfAsterisks

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    you don't use 'input' literally... you've named your scanner-input 'keyboard', so you need to use 'keyboard.next...'

  3. #3
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    "Cannot find symbol" messages occur when you mispell something, or when you give a method the wrong arguments.

    In your case you simply don't have a variable input declared anywhere. You called it something else.

  4. #4
    andy9507 is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default

    You just have to use the keyboard Scanner object you constructed earlier, instead of input which hasn't been defined and therefore is like gibberish to the compiler.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by andy9507 View Post
    You just have to use the keyboard Scanner object you constructed earlier, instead of input which hasn't been defined and therefore is like gibberish to the compiler.
    ... as already mentioned by ozzyman and pbrockway above.

  6. #6
    basla is offline Member
    Join Date
    Mar 2011
    Posts
    13
    Rep Power
    0

    Default

    Thanks so much for the helpful explanations. I get why it wasn't working now. Much appreciated!

Similar Threads

  1. "Cannot find symbol" errors in Java
    By 23Zone in forum New To Java
    Replies: 1
    Last Post: 02-17-2010, 08:13 AM
  2. Compiling probem "cannot find symbol"
    By thegluups in forum New To Java
    Replies: 27
    Last Post: 01-18-2010, 09:53 PM
  3. Error "can not find symbol variable"
    By FullMetalHollow in forum New To Java
    Replies: 5
    Last Post: 10-04-2009, 10:51 PM
  4. cannot find symbol for "list.addFirst"
    By alexbryan_08 in forum New To Java
    Replies: 10
    Last Post: 08-26-2009, 09:55 AM
  5. "Cannont find symbol Constructor" error
    By Welsh in forum New To Java
    Replies: 7
    Last Post: 01-25-2008, 01:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •