Hi all
I would really appreciate it if anyone could help me with a problem I am having compiling a small program that I am copying from a tutorial book.
I am running Java 2 v1.4.1, Win98SE, 950Mhz CPU, 256MB ram.
The code is as follows:
class SwitchApp{
public static void main (String args[]) {
System.out.println("Please enter Y/N"
char c = (char)System.in.read();
switch (c) {
case 'y': case 'Y':
System.out.println("Yes"
break;
case 'n': case 'N':
System.out.println("No"
break;
default:
System.out.println("Wrong answer."
break;
}
}
}
Everything above is exactly has it is in the book but I keep getting this error:
switchapp.java:4: unreported exception java.io.IOException; must be caught or declared to be thrown
char c = (char)System.in.read();
^
1 error.
The book shows no reference to this error but does state that the statement 'System.in' is seldom used in an application.
Please do not blind me with science with a solution to the problem as I have just started to look at Java and this would only serve to confuse me even more. What I would prefer is a reason as to why this is occuring.
I should say that I am using Notepad and compiling using the command line in the Dos window. All the other programs I have tried(2) out of the book work perfectly ok.
I am grateful in foresight to all who choose to answer.
Mick
I would really appreciate it if anyone could help me with a problem I am having compiling a small program that I am copying from a tutorial book.
I am running Java 2 v1.4.1, Win98SE, 950Mhz CPU, 256MB ram.
The code is as follows:
class SwitchApp{
public static void main (String args[]) {
System.out.println("Please enter Y/N"
char c = (char)System.in.read();
switch (c) {
case 'y': case 'Y':
System.out.println("Yes"
break;
case 'n': case 'N':
System.out.println("No"
break;
default:
System.out.println("Wrong answer."
break;
}
}
}
Everything above is exactly has it is in the book but I keep getting this error:
switchapp.java:4: unreported exception java.io.IOException; must be caught or declared to be thrown
char c = (char)System.in.read();
^
1 error.
The book shows no reference to this error but does state that the statement 'System.in' is seldom used in an application.
Please do not blind me with science with a solution to the problem as I have just started to look at Java and this would only serve to confuse me even more. What I would prefer is a reason as to why this is occuring.
I should say that I am using Notepad and compiling using the command line in the Dos window. All the other programs I have tried(2) out of the book work perfectly ok.
I am grateful in foresight to all who choose to answer.
Mick