Posted by 윤경구 on April 12, 1997 at 08:36:44:
In Reply to: [Q] java.io.IoException must be caught ....? posted by 양정윤 on April 12, 1997 at 03:09:41:
System.in은 InputStream 클래스 인스턴스입니다.
API 문서를 살펴보면 InputStream.read() 도구는 다음과 같이 선언되어 있습니다.
public abstract int read() throws IOException
class IfElseName {
public static void main (String args[]) {
char firstInitial=0;
System.out.println("Enter your first initial:");
try {
firstInitial = (char) System.in.read();
}catch(java.io.IOException e) {
e.printStackTrace();
}
if (firstInitial == -1)
System.out.println("Now what kind of name is that!?");
else if (firstInitial == 'j')
System.out.println("Your name must be Jules!");
else if (firstInitial == 'v')
System.out.println("Your name must be Vincent!");
else if (firstInitial == 'z')
System.out.println("Your name must be Zed!");
else
System.out.println("I can't figure out your name!");
}
}