Rotate String by n place. Lower Case keeps lower, upper keep upper
e.g. abc, 2 -> cde
abAB 2 -> cdCD
public String rotate(String str, int n) { char[] charArr = str.toCharArray(); for (int i = 0; i < charArr.length; i++) { if (!Character.isLetter(charArr[i])) { continue; } char base = Character.isUpperCase(charArr[i]) ? 'A' : 'a'; charArr[i] = (char)(base + ((charArr[i] - base + n) % 26)); } return new String(charArr); }