Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static boolean isPalindrome(String str) {
- return str.equals(new StringBuilder(str).reverse().toString());
- }
- public static void main(String []args) {
- int a = 2;
- int b = 10;
- int max = 40;
- int sum = 0;
- for (int i = 0; i < max; i++) {
- String x = Integer.toString(i, a);
- String y = Integer.toString(i, b);
- if (isPalindrome(x) && isPalindrome(y)) {
- sum += i;
- }
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement