0

Do you accept my challenge ?

Calculator.sum(String... numbers) return the sum of numbers (table of numbers) numbers contain always numbers of float as String This implementation return sometimes a false result, for example Calculator.sum("59.25", "2.30") return 61.54999999 Change the method sum to return always the right sum import java.math.*; class Calculator { static String sum(String... numbers) { double total = 0; for (String number : numbers) { total = total + number; } } }

11th Sep 2017, 8:33 PM
Seb
1 Odpowiedź
+ 4
convert 'number' to a double before adding it to the total. Then return total as a string. (Or change the rethrn type of the method to a double and just return total).
11th Sep 2017, 11:55 PM
Rrestoring faith
Rrestoring faith - avatar