title: Java parsing string input
body: <p>I'm having problem parsing a particular input case.  I'm using scanning class to deal with this. I tried using trim function but didn't seem to work. I guess one way to go about this is to use a Regular expression but how would I do that in this case? Any other solutions?
  The input I am having a problem with is :</p>
  
  <pre><code>55, 34, 12, 1
  </code></pre>
  
  <p>or</p>
  
  <pre><code>55, 34,      12, 1
  </code></pre>
  
  <p>Its when I put an input of spaces and not continuous commas.</p>
  
  <p>This input will work:</p>
  
  <pre><code>55,34,12,1
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>public class Excercise3
  
  
  {
  
      public static double round(double value, int places) 
      {
          if (places &lt; 0) throw new IllegalArgumentException();
  
          BigDecimal bd = new BigDecimal(value);
          bd = bd.setScale(places, RoundingMode.HALF_UP);
          return bd.doubleValue();
      }
  
  
      public static void main(String args[])
      {
  
          Scanner scan = new Scanner(System.in);  
         String test = scan.nextLine();   
       // String test = scan.next();      
          //test.trim();
          String delims = "[,]";        
          String[] strarray = test.split(delims);
  
  
          for (String str : strarray)
          {
  
              Integer numofWidgets = Integer.parseInt(str);
  
                  if (numofWidgets &gt; 0 &amp;&amp; numofWidgets &lt;= 12)
                  {                               
                      System.out.print("The widgets will cost " + (round(((numofWidgets * 12.39) + 3), 2) + "\n"));
                  }
                  else if ( numofWidgets &gt; 12 &amp;&amp; numofWidgets &lt;= 50 )
                  {
                      if (numofWidgets &gt; 30 )
                      {                       
                          System.out.print("The widgets will cost " + (round(((numofWidgets * 11.99) + 5), 2) + "\n"));
                      }
                      else
                      {
  
                          System.out.print("The widgets will cost " + (round(((numofWidgets * 11.99) + 3), 2) + "\n"));
                      }
                  }
                  else if (  numofWidgets &gt; 50)
                  {
  
                      System.out.print("The widgets will cost " + (round(((numofWidgets * 11.49) + 5), 2) + "\n"));
                  }
  
  
          }               
          scan.close(); 
  
      }
  
  
  
  }
  </code></pre>
  
  <p>Important fix: </p>
  
  <pre><code>String test = scan.nextLine();
  </code></pre>