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.
Stringalphabet="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//26+26 symbolsStringresult="";k=k%26;//correct rotate amountfor(inti=0;i<s.length();i++){CharactercurrentChar=s.charAt(i);intindex=alphabet.indexOf(currentChar);//get index of charif(index<26&&index+k>25//correct index if it goes abroad||index<52&&index+k>51){//for uppercaseindex-=26;}if(Character.isLetter(currentChar)){//if it not a char (-' e.t.c)result=result+alphabet.charAt(index+k);}else{result=result+s.charAt(i);}}returnresult;
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 →
Java with explain.