tags:

views:

74

answers:

3
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the String:");
String str = br.readLine();//error: must be caught or declared
String reverseStr="";
for(int i=str.length()-1;i>=0;--i) 
    reverseStr += str.charAt(i);

    System.out.println(reverseStr);

Should i include try catch block?

+4  A: 

The readLine() method can throw a checked exception (an IOException to be precise); you have to catch it or declare it in your prototype.


Resources :

Colin Hebert
thanks for giving me proper guidance.
Sumithra
+1  A: 

You need to catch/throw exception.

read line can throw IOException - If an I/O error occurs

So it must be taken care of

org.life.java
+1  A: 

Yes, or throw the exception out of your containing method.

Kevin D