Skip to main content
2 of 4
added 301 characters in body
TheCoffeeCup
  • 9.5k
  • 4
  • 38
  • 96

Your solution seems generally sound. I would make a few changes:

You are surrounding your whole code in a try-catch block. Instead, surround the area where the IOException has a chance of being thrown (Also, use System.err to print for errors):

try { BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); } catch (IOException) { System.err.println("Error"); } 

And since the in is inside the try-catch and it is required outside, do:

BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader( System.in)); } catch (IOException) { System.err.println("Error"); return; } 
TheCoffeeCup
  • 9.5k
  • 4
  • 38
  • 96