You are viewing a single comment's thread. Return to all comments →
Alternative solution using char arrays (Java):
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String s = in.next(); int r = in.nextInt(); String out = ""; char[] a = "abcdefghijklmnopqrstuvwxyz".toCharArray(); char[] b = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray(); for(int i = 0; i < s.length(); i++) { char c = s.charAt(i); if(!Character.isLetter(c)) { out += c; } for(int j = 0; j < a.length; j++) { if(c == a[j]) { out += a[(j+r)%a.length]; } if(c == b[j]) { out += b[(j+r)%a.length]; } } } System.out.println(out); } }
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 →
Alternative solution using char arrays (Java):