title: Exception in thread "main" java.lang.NumberFormatException: For input string: ""
body: <h2>Original Question</h2>
  
  <p>For the following small code I'm getting the error...</p>
  
  <pre><code>import java.io.*;
  
  class test
  {
  
      public static void main(String args[]) throws IOException 
      {
  
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          int i;
  
          System.out.println("Enter no of processes ");
  
          int no_of_process=Integer.parseInt(br.readLine());
          int process[]=new int[no_of_process];
  
          System.out.println("Enter the values");
  
          for(i=0;i&lt;no_of_process;i++)
              process[i]=Integer.parseInt(br.readLine());
  
          for(i=0;i&lt;no_of_process;i++)
              System.out.println(process[i]); 
  
      }
  }
  </code></pre>
  
  <p>Input:</p>
  
  <pre><code>Enter no of processes 
  5
  Enter the values
  1
  2
  Exception in thread "main" java.lang.NumberFormatException: For input string: ""
  at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
  at java.lang.Integer.parseInt(Integer.java:470)
  at java.lang.Integer.parseInt(Integer.java:499)
  at test.main(test.java:17)
  
  Process completed.
  </code></pre>
  
  <p>I think I have written the code properly and proper integer input is also given. How do I get rid of the above error without using any explicit exception handling statements? </p>
  
  <h2>Further Question:</h2>
  
  <p>Thanks guys for your answers...it is working. But there is one new question in my mind.</p>
  
  <p>I tried the following modification in the code and executed it. To my surprise, input was accepted properly without any run time error.</p>
  
  <pre><code>for(i=0;i&lt;no_of_process;i++)
      {
          System.out.println(Write anything or even keep it blank);
          process[i]=Integer.parseInt(br.readLine());
      }
  </code></pre>
  
  <p>By adding just one Print statement before (or even after) the input statement in the for loop, my program worked correctly and no exception was thrown while giving input.</p>
  
  <p>Can you guys explain the reason behind this?</p>
  
  <p>Again if I remove the Print statement from there, the same error gets repeated. I am really confused about the reason behind this. Please help.</p>