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

 

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

Write a method that scrambles a password using a prime-number 'jump' value. Return the scrambled string. For example, if the input parameter string is "ThisWasATest", and the 'jump' value was 5, you would build your resulting string this way: The first character would be the "T" from the first character of the original string. The next character is "a" because you jump 5 characters ahead. Next you jump ahead another 5 characters to get the "s" in test. The next jump would put you after the end of the string, so now you start the process over with the next character in from the front of the string. So now we add the "h" in "This", then jump to the "s" in "Was", then the "t" in "Test". The next jump would take us past the end of the string, so now we start over with the "i" in "This". The process continues until all of the characters have been rearranged following this patter. Here is a BIG hint: Use an array to build your new, scrambled string! Once you have the positions of all the characters figured out, build the resulting string from that array you made. You could also use an ArrayList if you prefer. As preconditions you may assume that the input string will have at least one character and that 'jump' will be a positive prime number (although for this pattern of jumping it would not really NEED to be prime).


test2021_02_25_SLHL_passwordScramble("ItIsDifficultToComeUpWithAllTheseStrings", 19) → "IUgtpsIWsiDtihfAflilcTuhletsTeoSCtormien"
test2021_02_25_SLHL_passwordScramble("abcdefghijklmnopqrstuvwxyz", 3) → "adgjmpsvybehknqtwzcfilorux"
test2021_02_25_SLHL_passwordScramble("abcdefghijklmnopqrstuvwxyz", 13) → "anbocpdqerfsgthuivjwkxlymz"

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

public String test2021_02_25_SLHL_passwordScramble(String pswrd, int jump) { }

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: 280

Copyright Nick Parlante 2017 - privacy