We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticStringcaesarCipher(Strings,intk){// Write your code hereStringBuffersb=newStringBuffer();intdk=k%26;for(inti=0;i<s.length();i++){charc=s.charAt(i);booleanupperAlpha=('A'<=c&&c<='Z')?true:false;charminChar=(upperAlpha)?'A':'a';charmaxChar=(upperAlpha)?'Z':'z';if(minChar<=c&&c<=maxChar){intencrypted=c+dk;if(encrypted>maxChar){encrypted=minChar+(encrypted-maxChar-1);}sb.append((char)encrypted);}else{sb.append(s.charAt(i));}}returnsb.toString();}
Cookie support is required to access HackerRank
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 →