Advertisement
Guest User

Untitled

a guest
Oct 12th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement