You are viewing a single comment's thread. Return to all comments →
Java 8
public static String caesarCipher(String s, int k) { return s.chars().map(codePoint -> { int letterCodePoint = codePoint; if (codePoint >= 'a' && codePoint <= 'z') letterCodePoint = 'a' + ((codePoint - 'a' + k) % ('z' - 'a' + 1)); if (codePoint >= 'A' && codePoint <= 'Z') letterCodePoint = 'A' + ((codePoint - 'A' + k) % ('Z' - 'A' + 1)); return letterCodePoint; }).collect(() -> new StringBuilder(s.length()), StringBuilder::appendCodePoint, StringBuilder::append).toString(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Caesar Cipher
You are viewing a single comment's thread. Return to all comments →
Java 8