Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class P4 {
- public static void main(String[] args)
- {
- int maxPal = 0;
- int current = 0;
- for (int i = 100; i < 1000; i++) {
- for (int j = 100; j < 1000; j++) {
- current = i*j;
- if (palindrome(current))
- {
- System.out.println(current + " is a palindrome from " + i + "x" + j);
- if (current > maxPal) {
- maxPal = current;
- }
- }
- }
- }
- System.out.println(maxPal);
- }
- public static boolean palindrome(int current)
- {
- String x = String.valueOf(current);
- boolean check = true;
- for (int i = 0; i <= x.length()/2; i++) {
- if (!(x.charAt(i) == x.charAt(x.length()-1-i)))
- {
- check = false;
- }
- }
- return check;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement