Ad

You have received 2 names.

Verify if the sum of letters of the 1 name is the same as sum of the letters of the 2 name. If the name or surname is null output NULL.

For example:

  1. "Anna" and "Nana"
    "Anna" = 65+110+110+97 = 382
    "Nana" = 78+97+110+97 = 382
    Result: "Anna" and "Nana" => "TRUE"

  2. "Sebastian" and "Patricia" => "FALSE"

  3. "John" and null => "NULL"

class Kata{
  
  public static String verifySum(String nameOne, String nameTwo) {
        int[] sumOfNames = new int[]{0, 0};
        
        if (nameOne == null || nameTwo == null) {
            return "NULL";
        }
        
        for (int i = 0; i < nameOne.length(); i++){
            sumOfNames[0] += nameOne.charAt(i);
        }
        
        for (int i = 0; i < nameTwo.length(); i++){
            sumOfNames[1] += nameTwo.charAt(i);
        }
        
        return sumOfNames[0] == sumOfNames[1] ? "TRUE" : "FALSE";
    }
}

Sebastian and Patricia want to know if the sum digits of their years is greater than the sum digits of their mother's years?

Example: (27,3,1)

  1. Mother = 27
  2. Sebastian = 3
  3. Patricia = 1

Calculate: (2+7) < (3+1) => false

public class AgeSumDigits
{
  public static boolean SumOfDigits(int[] ages) {   
  int m = ages[0];
  int s = ages[1];
  int p = ages[2];
  // Coding with passion ;)    
  return (calcSum(m) < calcSum(s)+calcSum(p)) ? true : false;
      
  } 
  
  static int calcSum(int age){
    int sum = 0;
    while(age>0){
      sum += age % 10;
      age /= 10;
    }
    return sum;
  }
}