Skip to content

Instantly share code, notes, and snippets.

@rahman99
Last active February 6, 2017 09:26
Show Gist options
  • Select an option

  • Save rahman99/5e8d3f814b7e39b88cf947775c129679 to your computer and use it in GitHub Desktop.

Select an option

Save rahman99/5e8d3f814b7e39b88cf947775c129679 to your computer and use it in GitHub Desktop.
sample encoding shifting character type
/**
* note: below sample only for alphabet, because it filter by Character.isLetter
*/
private static String encode(String line) {
char[] toEncode = line.toCharArray();
for (int i = 0; i < toEncode.length; i++) {
if (Character.isLetter(toEncode[i])) {
toEncode[i] = (char) ((toEncode[i] + 1 - (int)'a') % 26 + (int)'a');
}
}
line = String.valueOf(toEncode);
return line;
}
/**
* reverse number sample 1234 => 4321
*/
private static int reverseNumber(int num){
int reversenum = 0;
while( num != 0 )
{
reversenum = reversenum * 10;
reversenum = reversenum + num%10;
num = num/10;
}
return reversenum;
}
/**
* how to split number and alphabet in String using regex
*/
private static String[] splitNumberAndAphabet(String input){
return input.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment