Having a simple issue with the Scanner class...
Hi, doing a homework assignment in a intro to Java class, some reason the scanner class is giving me problems, I am typing the code as it appears in the text and getting the following error output. I am using vi to do the coding.
thanks for any help in advance.
Temperature.java:1: cannot resolve symbol
symbol : class Scanner
location: package util
import java.util.Scanner;
^
Temperature.java:13: cannot resolve symbol
symbol : class Scanner
location: class Temperature
Scanner scan = new Scanner (System.in);
Make your own Scanner class
Code:
public class MyScanner {
static BufferedReader console=new BufferedReader(new InputStreamReader(System.in));
// use it like
public int getUserInt() {
while (true) {
System.out.print("Please enter an integer value");
String s=console.readLine().trim();
try {
int iVal=Integer.parseInt(s);
return iVal;
} catch (NumberFormatException ne) {
System.err.println("["+s+"] is not not an integer);
} catch (IOException ioe) {
System.err.println("An error occured: "+ioe.getMessage());
}
System.out.println("Please reenter");
}
}
}
There is nothing you can do in 1.5 java that cannot be coded up in
1.4 java.