日期:2014-05-20 浏览次数:20876 次
import java.lang.Math; public class KeepFormatNumber { public static String doJudge(int n) { int sn =(int) Math.pow(n,2); int len = countLength(n); int times=1; for(int i=0;i<len;++i){ times*=10; } if((sn-(sn/times)*times)==n) return "YES"; else return "NO"; } private static int countLength(int n) { int len=0; while(n!=0){ n/=10; ++len; } return len; } public static void main(String[] args){ int n1 = 25; int n2 = 125; System.out.println("n1= "+n1+" result : "+KeepFormatNumber.doJudge(n1)); System.out.println("n2= "+n2+" result : "+KeepFormatNumber.doJudge(n2)); } }