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){returns.chars().map(c->{varisUpperLetter='A'<=c&&c<='Z';varisLowerLetter='a'<=c&&c<='z';if(isUpperLetter||isLowerLetter){varwrapStart=isUpperLetter?'A':'a';varwrapEnd=isUpperLetter?'Z':'z';varalphabetIdx=c-wrapStart;varalphabetSize=wrapEnd-wrapStart+1;varnewAlphabetIdx=(alphabetIdx+k)%alphabetSize;returnwrapStart+newAlphabetIdx;}else{// c is not alphabetical. Skip it.returnc;}}).collect(StringBuilder::new,StringBuilder::appendCodePoint,StringBuilder::append).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 →
Java 15 using streams API: