package margusmartseppcode.From_30_to_39; public class Problem_36 { static boolean palindrome(String p) { return p.equals(new StringBuilder(p).reverse().toString()); } static String dec2bin(int number) { return Integer.toString(number, 2); } public static void main(String[] args) { int sum = 0, size = 1000000; for (int i = 0; i < size; i++) sum += palindrome("" + i) && palindrome(dec2bin(i)) ? i : 0; System.out.println(sum); } }
No comments:
Post a Comment