This commit is contained in:
27
public/courses/prog-intro/homeworks/sum/SumDouble.java
Normal file
27
public/courses/prog-intro/homeworks/sum/SumDouble.java
Normal file
@@ -0,0 +1,27 @@
|
||||
// SumDouble.java
|
||||
|
||||
public class SumDouble {
|
||||
|
||||
public static void main(String[] args) {
|
||||
double sum = 0; // int -> double
|
||||
for (String argument : args) {
|
||||
StringBuilder number = new StringBuilder();
|
||||
for (char c : argument.toCharArray()) {
|
||||
if (!Character.isWhitespace(c)) {
|
||||
number.append(c);
|
||||
} else {
|
||||
if (!number.isEmpty()) {
|
||||
sum += Double.parseDouble(number.toString()); // Integer.parseInt -> Double.parseDouble())
|
||||
}
|
||||
number = new StringBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
if (!number.isEmpty()) {
|
||||
sum += Double.parseDouble(number.toString()); // Integer.parseInt() -> Double.parseDouble()
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(sum);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user