title: Trying to calculate a sum from input, when text is thrown in as well
body: <p>Have input passed through Scanner. It has both numbers and letters and spaces.</p>
  
  <p>Letters being stripped out, leaving only spaces and numbers.</p>
  
  <p>If I input without spaces, it works fine, but if I add spaces, it throws the error:</p>
  
  <blockquote>
    <p>java.lang.NumberFormatException: For input string: "" (in
    java.lang.NumberFormatException)</p>
  </blockquote>
  
  <p>This is applied against the line</p>
  
  <p>int dataInt = Integer.parseInt(data[i]);</p>
  
  <blockquote>
    <p>Stderr outputs
        java.lang.NumberFormatException: For input string: ""     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
      at java.lang.Integer.parseInt(Integer.java:592)     at
    java.lang.Integer.parseInt(Integer.java:615)  at
    Program2.main(Program2.java:21)</p>
  </blockquote>
  
  <p>Code is below</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Program2 {
  
  public static void main(String[] args) {
      Scanner kb = new Scanner(System.in);
      String input = kb.nextLine();
      input = input.replaceAll("[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]","");
      System.out.println(input);
      while(!input.equals("#")){
          String[] data = input.split(" ");
          int sum = 0;
          if (!input.equals("")){
              for(int i = 0; i &lt; data.length; i++){
                  int dataInt = Integer.parseInt(data[i]);
                  sum = sum + dataInt;
  
              }
  
          }
          System.out.println(sum);
          input = kb.nextLine();
      }
  } //main
  
  
  } // class Program2
  </code></pre>