-4

according to the following:

triangles.java:17: error: cannot find symbol
    shape = keyboard.nextChar();
                            ^
    symbol:   method nextChar()
    location: variable keyboard of type Scanner
1 error

why is it not finding symbol? i have keyboard initialized as the scanner. how would i fix this?

this is how i initialized it:

char shape;
shape = scanner.nextChar();

i have changed char to String, but that did nothing. i have imported a scanner, so thats not an issue.

  • 2
    What is `nextChar()`? Why would you think the error is on `shape`, when the error message says `cannot find symbol` and then tells you what symbol `symbol: method nextChar()` and the `location`? – Sotirios Delimanolis Mar 27 '14 at 00:14
  • 3
    `Scanner` doesn't have a `nextChar()` method. – arshajii Mar 27 '14 at 00:15
  • Your compilation error says `shape = keyboard.nextChar();`, but your code snippet says `shape = scanner.nextChar();` – aliteralmind Mar 27 '14 at 00:15
  • 2
    I believe you may find your answer in this post: http://stackoverflow.com/questions/13942701/take-a-char-input-from-the-scanner – Limnic Mar 27 '14 at 00:16

1 Answers1

0

If you're wanting to find the char within a String variable, just do something like:

 String str = scanner.nextLine(); // or scanner.next();
 char shape = str.charAt(i); // replace i with index of char you're trying to find.

hope that helps

user2277872
  • 2,896
  • 1
  • 18
  • 21