Problem 4 求回文数

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.

Answer:
906609

 

public class Palindromic { public static void main(String args[]){ int max=0; int mul=0; int ch=0; for(int i=999;i>100;i--){ for(int j=999;j>100;j--){ mul=i*j; if(isPalindromic(mul)){ ch=mul; if(max<=ch){ max=ch; } } } } System.out.println(max); } public static boolean isPalindromic(int num){ StringBuffer sb=new StringBuffer(""+num); int num2=Integer.parseInt(sb.reverse().toString()); if(num==num2){ return true; } return false; } }

你可能感兴趣的:(String,Class,Numbers)