Results 1 to 6 of 6
- 04-23-2011, 12:21 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
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
-
you don't use 'input' literally... you've named your scanner-input 'keyboard', so you need to use 'keyboard.next...'
- 04-23-2011, 12:24 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
"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.
- 04-23-2011, 08:29 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
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.
-
- 04-24-2011, 03:21 PM #6
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
"Cannot find symbol" errors in Java
By 23Zone in forum New To JavaReplies: 1Last Post: 02-17-2010, 07:13 AM -
Compiling probem "cannot find symbol"
By thegluups in forum New To JavaReplies: 27Last Post: 01-18-2010, 08:53 PM -
Error "can not find symbol variable"
By FullMetalHollow in forum New To JavaReplies: 5Last Post: 10-04-2009, 09:51 PM -
cannot find symbol for "list.addFirst"
By alexbryan_08 in forum New To JavaReplies: 10Last Post: 08-26-2009, 08:55 AM -
"Cannont find symbol Constructor" error
By Welsh in forum New To JavaReplies: 7Last Post: 01-25-2008, 12:12 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks