why cant i read this single character?
char c = 'Y';
while(c == 'y' || c == 'Y'){
//stuff happens..
}
c = (char)System.in.read(); <----error
I get a compilation error that says “Unhandled exception type IOException”
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have 2 options to solve this:
Handle the exception using a try-catch statement as shown below:
Below the package statement in class (if any), add an import statement like:
2.
Add a throws clause after the function indicating that the funcion may throw a checked exception. In this case you may want to handle the exception in the calling function.
Example: Suppose function sample () calls test()
Below the package statement in class (if any), add an import statement like:
In case 2 you may handle the exception in sample() else the exception (if occurred) will propagate upwards until it is handled.