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

 

orion.a.smith@gmail.com apcsa-encryption > apcsaEncryptRotateEvens
prev  |  next  |  chance

Given an input plaintext, rotate the even-indexed characters (starting with the first character, index 0) into subsequent even positions. A rotation implies that the last character with an even index will become the new first character with index 0. Do this rotation a number of times equal to the length of the plaintext divided by 4 (use integer division). As an example consider the plaintext "012345678" (length 9). This plaintext will cause 2 rotations (9/4 == 2 when leaving aside remainders). After the first rotation it would read as "810325476", after the second rotation "618305274".

HINT
Consider an outer for loop, since this method has to accomplish the rotation task a set number of times. Also note that this method is going to work slightly differently on inputs with odd vs. even lengths.

apcsaEncryptRotateEvens("012345678") → "618305274"
apcsaEncryptRotateEvens("We meet at Dawn for the raid") → "nefmret etrDiwW oe tha aad"
apcsaEncryptRotateEvens("Pi is approximately equal to 3.14159265359") → "uilit p.r4x5m2t5l5 Pq as aop3o1i1a9e6y3e9"

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

public String apcsaEncryptRotateEvens(String str) { }

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

Copyright Nick Parlante 2017 - privacy