Reputation: 31
I have the below inside of a class and it's returning an error.
My teacher had told me I can create an instance variable out of the scanner object if I instantiate it in the constructor and import the java.util.Scanner package.
Why won't the below work?
import java.util.Scanner;
public class Javaio {
private char scanner;
public Javaio() {
scanner = new Scanner(System.in);
}
}
Upvotes: 0
Views: 2105
Reputation: 181
Scanner is a class.. you seem to have misunderstood the concept a little( or probably tired of it)
simple declare a new object of the Scanner class..
Scanner scanner=new Scanner(System.in);
Upvotes: 0
Reputation: 178303
A Scanner
is not a char
. Change the datatype of scanner
to match:
private Scanner scanner;
Upvotes: 2