• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create a Scanner class?  RSS feed

 
Kerry Cotter
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



produced javac results:

symbol : class Scanner
location: class vidal
Scanner keyboard = new Scanner(System.in);
^
vidal.java:11: cannot find symbol
symbol : class Scanner
location: class vidal
Scanner keyboard = new Scanner(System.in);
^
2 errors
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kerry Cotter wrote:produced javac results:

Kerry,

Please DontWriteLongLines. It makes your thread very hard to read. I've broken yours up this time, but for future reference, please remember:
80 characters max.
(the SSCCE page actually recommends 62)
And that includes string literals AND comments.

Thanks.

And the reason you're getting the error - I suspect - is because you haven't got an 'import' statement for your Scanner class.

Winston
 
Kerry Cotter
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do I found a Scanner import? Is this a boilerplate of some sort? All I want to do is take the keyboard input data. I can do this in Python but Java continues to mystify me.

Thanks
 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either import the class in order to create an instance of it:

import java.util.Scanner;

or you can create an instance of the class the long way but I wouldn't do it this way:

java.util.Scanner sc = new java.util.Scanner(System.in);
 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kerry,

Java is not like python.......

When you import a file in python, the code imported is executed right there.

The import in java is much different - java expects all classes to be used on the classpath (either explicit or implicit) and the import is just syntactic sugar so instead of
writing java.util.Scanner you can just reverence Scanner.

In your code, you referenced Scanner which it couldnt find.

-steve
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!