daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class Test {
  3.    
  4.    
  5.     public static boolean isPalindrome(String str) {
  6.         return str.equals(new StringBuilder(str).reverse().toString());
  7.     }
  8.  
  9.     public static void main(String []args) {
  10.         int a = 2;
  11.         int b = 10;
  12.         int max = 40;
  13.        
  14.         int sum = 0;
  15.        
  16.         for (int i = 0; i < max; i++) {
  17.             String x = Integer.toString(i, a);
  18.             String y = Integer.toString(i, b);
  19.             if (isPalindrome(x) && isPalindrome(y)) {
  20.                 sum += i;
  21.             }
  22.         }
  23.        
  24.         System.out.println(sum);
  25.     }
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top