public class AgeSumDigits { public static boolean SumOfDigits(int[] ages) { int m = ages[0]; int s = ages[1]; int p = ages[2]; String mS = String.valueOf(m); String cS = String.valueOf(s) + String.valueOf(p); return mS.chars().map(c -> c - '0').sum() < cS.chars().map(c -> c - '0').sum(); } }
- 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;}- String mS = String.valueOf(m);
- String cS = String.valueOf(s) + String.valueOf(p);
- return mS.chars().map(c -> c - '0').sum() < cS.chars().map(c -> c - '0').sum();
- }
- }
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class SolutionTest { AgeSumDigits asd = new AgeSumDigits(); @Test public void testSumDigits() { assertEquals(false, asd.SumOfDigits(new int[]{27,3,1})); assertEquals(true, asd.SumOfDigits(new int[]{33,9,7})); assertEquals(true, asd.SumOfDigits(new int[]{50,26,24})); assertEquals(false, asd.SumOfDigits(new int[]{20,1,1})); } }
- import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import org.junit.runners.JUnit4;
- public class SolutionTest {
- AgeSumDigits asd = new AgeSumDigits();
- @Test
- public void testSumDigits() {
- assertEquals(false, asd.SumOfDigits(new int[]{27,3,1}));
- assertEquals(true, asd.SumOfDigits(new int[]{33,9,7}));
- assertEquals(true, asd.SumOfDigits(new int[]{50,26,24}));
- assertEquals(false, asd.SumOfDigits(new int[]{20,1,1}));
- }
- }
class Kata{ public static String verifySum(String nameOne, String nameTwo) { if (nameOne == null || nameTwo == null) { return "NULL"; } return nameOne.chars().sum() == nameTwo.chars().sum() ? "TRUE" : "FALSE"; } }
- 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";- return nameOne.chars().sum() == nameTwo.chars().sum() ? "TRUE" : "FALSE";
- }
- }