id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > test2024_09_19_HL_codex
prev  |  next  |  chance

Write a RECURSIVE solution to this problem. Your solution MUST use recursion in a meaningful way. You may not use any loops anywhere in your solution. I recommend using a helper method to avoid using the lengthy method name. This method accepts an array of TEN single digit integers and an integer called 'origNum'. This method returns a new integer where each digit in 'origNum' has been replaced with a digit from 'digits' such that the value of the digit in 'origNum' is the index in 'digits' in which to find the new digits. I understand that the above paragraph is hard to comprehend. So here is an example: Supposed 'digits' is {5,2,1,9,4,4,4,1,1,1} and 'origNum' is 578132. In that case you would return 411291. The logic behind this is that each digit in 'origNum' indicates a position in 'digits' to find the new digit. So the 5 in 'origNum' means to look in index 5 in 'digits'. At that location there is a 4, so that 5 becomes a 4. Likewise, the 7 in 'origNum' means to look in index 7 of 'digits' which contains a 1. The entire new number is constructed from the old number ('origNum') this way. While recursion is REQUIRED for this problem, that requirement will probably help you as it is much easier to do recursively anyway. Think recursively and you should do fine! Also, as always, don't forget to examine the test data and make sure you understand those results. HINT: I used a helper method, just so I could shorten the method name. I wrote the original method with a body of just one line of code. The helper method also only had one line of code in the body. Don't make this harder than it is!


test2024_09_19_HL_codex([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 89352) → 89352
test2024_09_19_HL_codex([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 34078) → 45189
test2024_09_19_HL_codex([8, 1, 3, 2, 3, 1, 8, 2, 1, 8], 123456) → 132318

...Save, Compile, Run (ctrl-enter)

public int test2024_09_19_HL_codex(int[] digits, int origNum) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 410

Copyright Nick Parlante 2017 - privacy