Question: ```
package testing.project;

public class PalindromeThreeDigits {

    public static void main(String[] args) {
        int value = 0;
        for(int i = 100;i <=999;i++)
        {
            for(int j = i;j <=999;j++)
            {
                int value1 = i * j;
                StringBuilder sb1 = new StringBuilder(""+value1);
                String sb2 = ""+value1;
                sb1.reverse();
                if(sb2.equals(sb1.toString()) && value<value1) {
                    value = value1;

                }

            }
        }

        System.out.println(value);
    }
}

```

This is the code that I wrote in Java... Is there any efficient way other than this.. And can we optimize this code more??

Answer: 
```
public class Pin
{
    public static boolean isPalin(int num)
    {
        char[] val = (""+num).toCharArray();
        for(int i=0;i<val.length;i++)
        {
            if(val[i] != val[val.length - i - 1])
            {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args)
    {
        for(int i=999;i>100;i--)
            for(int j=999;j>100;j--)
            {
                int mul = j*i;
                if(isPalin(mul))
                {
                    System.out.printf("%d * %d = %d",i,j,mul);
                    return;
                }
            }
    }
}

```
You can try the following which prints

```
999 * 979 * 989 = 967262769
largest palindrome= 967262769 took 0.015

```

---

```
public static void main(String... args) throws IOException, ParseException {
  long start = System.nanoTime();
  int largestPalindrome = 0;
  for (int i = 999; i > 100; i--) {
    LOOP:
    for (int j = i; j > 100; j--) {
      for (int k = j; k > 100; k++) {
        int n = i * j * k;
        if (n < largestPalindrome) continue LOOP;
        if (isPalindrome(n)) {
          System.out.println(i + " * " + j + " * " + k + " = " + n);
          largestPalindrome = n;
        }
      }
    }
  }
  long time = System.nanoTime() - start;
  System.out.printf("largest palindrome= %d took %.3f seconds%n", largestPalindrome, time / 1e9);
}

private static boolean isPalindrome(int n) {
  if (n >= 100 * 1000 * 1000) {
    // 9 digits
    return n % 10 == n / (100 * 1000 * 1000)
        && (n / 10 % 10) == (n / (10 * 1000 * 1000) % 10)
        && (n / 100 % 10) == (n / (1000 * 1000) % 10)
        && (n / 1000 % 10) == (n / (100 * 1000) % 10);
  } else if (n >= 10 * 1000 * 1000) {
    // 8 digits
    return n % 10 == n / (10 * 1000 * 1000)
        && (n / 10 % 10) == (n / (1000 * 1000) % 10)
        && (n / 100 % 10) == (n / (100 * 1000) % 10)
        && (n / 1000 % 10) == (n / (10 * 1000) % 10);
  } else if (n >= 1000 * 1000) {
    // 7 digits
    return n % 10 == n / (1000 * 1000)
        && (n / 10 % 10) == (n / (100 * 1000) % 10)
        && (n / 100 % 10) == (n / (10 * 1000) % 10);
  } else throw new AssertionError();
}

```