4.Palindromic Number

A palindromic number reads the same both ways. The largest palindrome made from the  product of two 2-digit numbers is 9009 = 91 × 99.  Find the largest palindrome made from the product of two 3-digit numbers.

public class Problem4 {
    public void palindromic() {
        int hp = 0;
        for (int i=999;i>100;i--) {
            for (int j=i;j>100;j--) {
                    int ij =i * j;
                    int rij = 0, n= ij;
                    while(n>0){
                        rij=rij*10+n%10;
                        n=n/10;
                    }
                    if (ij<=hp)  break;
                    if (ij==rij ) {
                        hp = ij;
                        //System.out.println("Equals " +  i + " - " + j + " - " + ij);
                    }
                
            }
        }
        System.out.println(hp);
    }

    public static void main(String[] args) {
        Problem4 p = new Problem4();
        p.palindromic ();
    }
}
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: