Question: The following questions be solved using only a recursive method . Coding language : Java Questions /** * * @param n * @param d: single

The following questions be solved usingonly a recursive method.

Coding language : Java

Questions

/** * * @param n * @param d: single digit integer * @return the number of occurrences of digit d in integer n, * except when target (d) appears twice in a row, * the second one counts twice * * For example, * * if countWeighted(8818, 8) returns 4. * * Explanation: * * First 8 (from left) contributes 1 * Second 8 contributes 2 (since there is another 8 immediately to its left) * Third 8 contributes 1 * * Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), * while divide (/) by 10 removes the rightmost digit (126 / 10 is 12). */ public int countWeighted(int n, int d) { return 0; //to be completed }

/** * * @param str * @param tokens * @return true if str contains all characters from token, false otherwise * Note if tokens contains multiple occurrences of a particular character, * then str must have at least as many occurrences of that character. */ public boolean contains(String str, String tokens) { return false; //to be completed }

Test Cases

@Test public void testCountWeighted() { assertEquals(5, testObject.countWeighted(888, 8)); assertEquals(3, testObject.countWeighted(88, 8)); assertEquals(2, testObject.countWeighted(808, 8)); assertEquals(1, testObject.countWeighted(8, 8));

assertEquals(5, testObject.countWeighted(707070707, 7)); assertEquals(4, testObject.countWeighted(707070707, 0)); assertEquals(17, testObject.countWeighted(777777777, 7)); }

@Test public void testContainsStringString() { assertTrue(testObject.contains("man", "nma")); assertTrue(testObject.contains("superman", "amen")); assertTrue(testObject.contains("superman", "")); assertTrue(testObject.contains("", "")); assertFalse(testObject.contains("environmentally prudent scheme", "pool")); assertTrue(testObject.contains("environmentally prudent scheme", "pedestrian")); assertFalse(testObject.contains("environmentally prudent scheme", "xoxo")); assertFalse(testObject.contains("environmentally prudent scheme", "scheme!")); assertFalse(testObject.contains("environmentally prudent scheme", "Scheme")); //uppercase 'S' }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!