Browse Source

first one done

master
Raphael Roberts 7 years ago
parent
commit
d277a3e98a
  1. 15
      ParseString.java
  2. 2
      TestParseString.java

15
ParseString.java

@ -0,0 +1,15 @@
public class ParseString{
private String str;
public ParseString(String str){
this.str = str;
}
public double sumOfAll(){
String new_str = this.str.replaceAll(" +",",");
String[] parts = new_str.split(",");
double total = 0;
for (int i = 0; i < parts.length; i ++){
total += Double.parseDouble(parts[i]);
}
return total;
}
}

2
TestParseString.java

@ -2,7 +2,6 @@ public class TestParseString
{
public static void main(String[] args)
{
/*
String s1 = "12.3,4.9 6,9 0,8";
ParseString ps1 = new ParseString(s1);
System.out.println("Sum of all number in \"" + s1 + "\" is: ");
@ -14,6 +13,5 @@ public class TestParseString
System.out.println("Sum of all number in \"" + s2 + "\" is: ");
System.out.println(ps2.sumOfAll());
System.out.println();
*/
}
}
Loading…
Cancel
Save