The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
long result = 0; for (long i = 0; i < 1000000; i++) { StringBuilder tempdec = new StringBuilder(Long.toString(i)); if (tempdec.toString().equals(tempdec.reverse().toString())) { StringBuilder tempbin = new StringBuilder(Long.toBinaryString(i)); if (tempbin.toString().equals(tempbin.reverse().toString())) { result = result + i; } } } System.out.println(result);
Lösung: 872187