Hi All,
I'm trying to learn
Java through a couple of books and I need help. I haven't been able to compile a program that I copied exactly as written from the book. Here's the code:
public class Reply {
public static void main(
String[] args) {
char a;
System.out.println("Enter a number from 1-3:");
a = (char)System.in.read();
switch(a) {
case '1':
System.out.println("\nYou win a car!");
break;
case '2':
System.out.println("\nYou picked the goat");
break;
case '3':
System.out.println("\nYou get to keep your 100");
break;
default:
System.out.println("\nIncorrect entry");
}
}
}
The problem is in the line of code:
a = (char)System.in.read();
The compiler puts a pointer under the parenthesis and says:7:Exception java.io.
IOException must be caught, or it must be declared in the throws clause of this method.
Would someone help me?
Thanks in advance.
Mike B.