Last active
February 6, 2017 09:26
-
-
Save rahman99/5e8d3f814b7e39b88cf947775c129679 to your computer and use it in GitHub Desktop.
sample encoding shifting character type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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