add all variants for 'Sum' task (hw2)
This commit is contained in:
23
java/sum/SumDouble.java
Normal file
23
java/sum/SumDouble.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package sum;
|
||||
|
||||
/**
|
||||
* @author Nikita Doschennikov (me@fymio.us)
|
||||
*/
|
||||
public class SumDouble {
|
||||
public static void main(String[] args) {
|
||||
double res = 0.0; // 0_0
|
||||
for (String arg : args) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (char c : arg.toCharArray()) {
|
||||
if (!Character.isWhitespace(c)) {
|
||||
builder.append(c);
|
||||
} else {
|
||||
res += (!builder.toString().isEmpty()) ? Double.parseDouble(builder.toString()) : 0;
|
||||
builder = new StringBuilder();
|
||||
}
|
||||
}
|
||||
res += (!builder.toString().isEmpty()) ? Double.parseDouble(builder.toString()) : 0;
|
||||
}
|
||||
System.out.println(res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user