Ad
Code
Diff
  • public class StringCalculator{
      
      public static int add(String numbers){
        if(numbers == "") {
          return 0;
        }
        
        String[] numbersArr = numbers.split(",");
        if (numbersArr.length > 1) {
          int result = Integer.parseInt(numbersArr[0]) + Integer.parseInt(numbersArr[1]);
          return result;
        }
        return Integer.parseInt(numbers);
      }
      
    }
    • public class StringCalculator{
    • public static int add(String numbers){
    • if(numbers == "") {
    • return 0;
    • }
    • return 1;
    • String[] numbersArr = numbers.split(",");
    • if (numbersArr.length > 1) {
    • int result = Integer.parseInt(numbersArr[0]) + Integer.parseInt(numbersArr[1]);
    • return result;
    • }
    • return Integer.parseInt(numbers);
    • }
    • }