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.
Bookmarks