You are viewing a single comment's thread. Return to all comments →
Easy Java Solution:
public class Solution { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); String word = s.next(); int k = s.nextInt(); StringBuilder sb = new StringBuilder(); for(int i = 0; i < n; ++i) { sb.append(encryptChar(word.charAt(i), k)); } System.out.println(sb.toString()); } private static char encryptChar(char c, int k) { if(!Character.isAlphabetic(c)) return c; int base = Character.isLowerCase(c) ? 'a' : 'A'; return (char)((c + k - base) % 26 + base); } }
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 →
Easy Java Solution: