Question
Write a method that sums every second digit, right to left. * If doubling results in a double-digit, * add up the digits to produce
Write a method that sums every second digit, right to left.
* If doubling results in a double-digit,
* add up the digits to produce a single.
* 4388576018402626 =>
* 2*2 = 4
* +2*2 = 4
* +2*4 = 8
* +2*1 = 2
* +2*6 = 12 => 3
* +2*5 = 10 => 1
* +2*8 = 16 => 7
* +2*4 = 8
* = 37
public static int sumOfDoubleEvens(String s) {
}
Here are the test cases that the code should cover.
_testSumOfDoubleEvens("", 0);
_testSumOfDoubleEvens("0", 0);
_testSumOfDoubleEvens("1", 0);
_testSumOfDoubleEvens("2", 0);
_testSumOfDoubleEvens("9", 0);
_testSumOfDoubleEvens("00", 0);
_testSumOfDoubleEvens("11", 2);
_testSumOfDoubleEvens("22", 4);
_testSumOfDoubleEvens("99", 9);
_testSumOfDoubleEvens("03", 0);
_testSumOfDoubleEvens("52", 1);
_testSumOfDoubleEvens("27", 4);
_testSumOfDoubleEvens("98", 9);
_testSumOfDoubleEvens("30", 6);
_testSumOfDoubleEvens("25", 4);
_testSumOfDoubleEvens("72", 5);
_testSumOfDoubleEvens("89", 7);
_testSumOfDoubleEvens("4388576018402626", 37);
_testSumOfDoubleEvens("5117275325077359", 18);
_testSumOfDoubleEvens("378282246310005", 27);
_testSumOfDoubleEvens("371449635398431", 47);
_testSumOfDoubleEvens("378734493671000", 32);
_testSumOfDoubleEvens("6011111111111117", 17);
_testSumOfDoubleEvens("5555555555554444", 22);
_testSumOfDoubleEvens("5105105105105100", 7);
_testSumOfDoubleEvens("4012888888881881", 47);
_testSumOfDoubleEvens("4222222222222", 24);
Please help with this I have my own code but I need to reference it to someone else's.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started