You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
390 B

7 years ago
  1. public class ParseString{
  2. private String str;
  3. public ParseString(String str){
  4. this.str = str;
  5. }
  6. public double sumOfAll(){
  7. String new_str = this.str.replaceAll(" +",",");
  8. String[] parts = new_str.split(",");
  9. double total = 0;
  10. for (int i = 0; i < parts.length; i ++){
  11. total += Double.parseDouble(parts[i]);
  12. }
  13. return total;
  14. }
  15. }