title: Computing the sum of values that came from a split String in an array in Java
body: <p>Basically I am wondering how I could make a method that takes a String that has a series of decimal numbers separated by spaces and then (after splitting the string according to separate numbers) returns a double. Then using the doubles returned, returning the sum of all the decimal numbers rounded to the nearest whole number.</p>
  
  <p>Example: Like let's say I input String “42.5 7.2 1.2” and I want to make it return the sum of all the decimal numbers rounded to the nearest whole number, which here would be 51.0.</p>
  
  <p>Here is my attempt so far.</p>
  
  <pre><code>String s = text1; 
  String[] ls;
  ls = s.split(" ");
  for(int i = 0; i&lt;= s.length(); i++){ 
      double a = Double.parseDouble(ls[i]);
  </code></pre>