title: How to avoid NumberFormatException while using BufferedReader?
body: <p>I used BufferedReader to read data from the user, but it gives NumberFormat Exception prvovided I give the input in a certain way. Suppose in C, I write the code like this:</p>
  
  <pre><code>scanf("%d %d", &amp;x, &amp;y);
  </code></pre>
  
  <p>and i try to give the input to the console like this :  <strong>23 45</strong>, it assigns values like this:</p>
  
  <blockquote>
    <p>x = 23, y = 45</p>
  </blockquote>
  
  <p>How can I do something like this in java. I tried like this :</p>
  
  <pre><code>BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
  BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
  String line1 = br1.readLine();
  String line2 = br2.readLine();
  int x = Integer.parseInt(line1);
  int y = Integer.parseInt(line2);
  </code></pre>
  
  <p>But this gives:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NumberFormatException: For input
    string: "23 45"   at
    java.lang.NumberFormatException.forInputString(Unknown Source)    at
    java.lang.Integer.parseInt(Unknown Source)    at
    java.lang.Integer.parseInt(Unknown Source)    at AB.main(AB.java:23)</p>
  </blockquote>