1

I get this error when trying to use the Scanner object:

Main.java:105: error: cannot find symbol

The Scanner library is already imported

Here is my code :

Scanner in= new Scanner(System.in);
public int play(int pieces){
    Scanner in= new Scanner(System.in); 
    int num;
    num = in.nextInt();

    return pieces-in;
}
Bibz
  • 321
  • 2
  • 11
mr_ecko
  • 61
  • 1
  • 1
  • 6

1 Answers1

0

in is you Scanner object. The value you read is in the variable num, you must use that variable in the return statement.

public int play(int pieces){
    Scanner in= new Scanner(System.in); 
    int num;
    num = in.nextInt();

    return pieces-num;
}
Bibz
  • 321
  • 2
  • 11
  • 1
    Look at this post, is it possible you didn't create the packages structure ? http://stackoverflow.com/questions/6777554/cannot-find-symbol-error-even-on-a-ridiculously-simple-example – Bibz Jul 13 '15 at 18:27
  • The code is good, I tested it successfully, so it must be something with how you compile or un it. You might also want to check : http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean – Bibz Jul 13 '15 at 18:31
  • i see it could be lots of things. i will try a few things. thx. at least i know the code is good. – mr_ecko Jul 13 '15 at 18:37