Hard
This code
public final class StringCalculator {
  private static final String SEPARATOR = ",|\n";
  private StringCalculator() {}
  public static String sum(String numbers) {
    if (noNumbers(numbers)) {
      return "0";
    }
    return Arrays.stream(numbers.split(SEPARATOR))
        .map(BigDecimal::new)
        .reduce(BigDecimal.ZERO, BigDecimal::add)
        .toPlainString();
  }
  private static boolean noNumbers(String numbers) {
    return numbers == null || numbers.isBlank();
  }
}
Author: Clément DevosStatus: PublishedQuestion passed 169 times
Edit
0
Community EvaluationsNo one has reviewed this question yet, be the first!
1
What does SRP stand for?4
Write a function that returns the first character of a string in Java1
Which Java 7 feature was only usable in Java 8?4
This code allows to randomly get numbers between 1 to 31 in results. Should have declard SimpleDateFormat in the Thread.1
A Java class that converts Arabic numbers to Roman numerals.1
Write a Java implementation of the FizzBuzz code kata.1
Java code that replaces keys in a template with their values.