Created
April 17, 2017 20:31
-
-
Save LuxXx/e8952c697aae6e22f81b5f53a45a9627 to your computer and use it in GitHub Desktop.
Project Euler - Problem 36
This file contains 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
package euler; | |
public class BasePalindrome { | |
public static void main(String[] args) { | |
int sum = 0; | |
for (int i = 0; i < 1_000_000; i++) { | |
if (isPalindrome(Integer.valueOf(i).toString()) && isPalindrome(Integer.toBinaryString(i))) { | |
sum += i; | |
} | |
} | |
System.out.println(sum); | |
} | |
public static boolean isPalindrome(String s) { | |
for (int i = 0; i < s.length() / 2; i++) { | |
if (s.charAt(i) != s.charAt(s.length() - i - 1)) return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment