-6

/* In this above example when it will display output of Catch i.e. [Error May be Occured in Input]. Please give me the input. */

 import java.io.IOException; 
    public class ThrowsClause 
    { 
         static boolean guess() throws IOException //Throws Clause
         { 
             char ch='r'; 
             System.out.print("Guess any Character(a-z) : "); 
             char n=(char)System.in.read(); 
             return(ch==n); 
          } 
         public static void main(String[] args) 
         { 
              boolean result; 
              try 
             { 
                  result=guess(); //Back to method
                  if(result==true) 
                     System.out.println("Your Guess is Perfect"); 
                  else 
                     System.out.println("Your Guess is Incorrect"); 
              } 
                  catch(IOException e) 
              { 
                     System.out.println("Error May be Occured in Input"); //I want input to display this statement as a output`
               } 
          } 
    } 

/* In this above example when it will display output of Catch i.e. [Error May be Occured in Input]. Please give me the input. */
Ravi
  • 30,829
  • 42
  • 119
  • 173

1 Answers1

0

Your program will only print the Error May be Occured in Input message if an IOException occurs. The Javadocs state that this will only happen if an input/output error occurs while getting user input.

Adil B
  • 14,635
  • 11
  • 60
  • 78