← all problems

caesarShiftString 🌶️🌶️🌶️ Extra

Write a method that takes one String parameter, s, and one int parameter, shift, and returns a new String with every character Caesar-shifted by shift positions (wrapping 'z' back around to 'a'), same as in caesarShiftChar. You can assume s contains only lowercase letters (no spaces or punctuation), and shift is always between 0 and 25, inclusive. caesarShiftString("abc", 1) returns "bcd". caesarShiftString("xyz", 3) returns "abc" (every letter wraps around). Hint: walk through s one character at a time with a while loop, shifting each character the same way caesarShiftChar does, and build up the result with string concatenation.