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'); | |
| } | |
| } |
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
| /** | |
| * this is to check letter alphabet: | |
| */ | |
| char chr = 'b'; | |
| chr = (char) (chr + 4); | |
| System.out.println(chr); | |
| --output--> f | |
| note: but this way is not suitable if the next letter is more than z. |
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
| private static boolean isPrime(int number){ | |
| if(number<=1) | |
| return false; | |
| for(int i=2;i<Math.sqrt(number);i++){ | |
| if(number % i ==0) | |
| return false; | |
| } | |
| return true; | |
| } |
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
| int bilangan = 3; | |
| int pangkat = 122; | |
| int result=1; | |
| int n=0; | |
| int hasilPangkat; | |
| while(pangkat > 0){ | |
| hasilPangkat = (int)Math.pow(2, n); | |
| if(pangkat % 2 == 0) | |
| hasilPangkat=0; | |
| pangkat = pangkat/2; |
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
| private static String RomanNumerals(int value){ | |
| LinkedHashMap<String, Integer> roman_numerals = new LinkedHashMap<String,Integer>(); | |
| roman_numerals.put("M", 1000); | |
| roman_numerals.put("CM", 900); | |
| roman_numerals.put("D", 500); | |
| roman_numerals.put("CD", 400); | |
| roman_numerals.put("C", 100); | |
| roman_numerals.put("XC", 90); | |
| roman_numerals.put("L", 50); |
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
| //file auto must be detect log4j.properties in source | |
| import org.apache.log4j.Logger; | |
| public class HelloExample{ | |
| final static Logger logger = Logger.getLogger(HelloExample.class); | |
| final static Logger log = Logger.getLogger("logging"); | |
| public static void main(String[] args) { | |
| HelloExample obj = new HelloExample(); |
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
| import org.apache.log4j.ConsoleAppender; | |
| import org.apache.log4j.FileAppender; | |
| import org.apache.log4j.Level; | |
| import org.apache.log4j.Logger; | |
| import org.apache.log4j.PatternLayout; | |
| public class ProgramaticLog4j { | |
| public static void main(String[] arg){ | |
| PatternLayout layout = new PatternLayout(); |