大家看看这个编程题
在小于99999的正整数中,求出既是完全平方数,又有两个相同数的数,例如:144
------解决方案--------------------public class csdn03
{
public static void main(String [] args)
{
for(double i=1;i <=99999;i++)
{
double d1 = Math.sqrt(i);
long l1 = Math.round(d1);
if(d1-l1==0)
{
String result = String.valueOf((int)i);
if(fun(result))
{
System.out.println(result);
}
}
}
}
public static boolean fun(String s)
{
char [] ch = s.toCharArray();
int num=0,num1=0;
for(int i=0;i <ch.length;i++)
{
num=0;
for(int j=i;j <ch.length;j++)
{
if(ch[i]==ch[j])
{
num++;
}
else
{
break;
}
}
if(num==2)
{
num1++;
}
}
if(num1==1)
{
return true;
}
else
{
return false;
}
}
}
------解决方案--------------------public class FindNumber {
public static void main(String[] args) {
for(long i=0;;i++){
long temp=i*i;
String number =String.valueOf(temp);
if(temp <99999){
if(isRight(number))
System.out.println(temp);
}
else{
break;
}
}
}
public static boolean isRight(String number){
boolean result=false;
int [] num = new int[10];
char [] num1 = number.toCharArray();
for(int i=0;i <num1.length;i++){
int n = num1[i]-48;
if(n> =0&&n <=9){
num[n]++;
if(num[n]> 1){
result=true;
break;
}
}
}
return result;
}
}
------解决方案--------------------public class test {
public static void main (String arg[]) {
int i=0;
while(i*i <99999) {
String k=Integer.toString(i*i);
boolean ok=false;
for(int j=0; j <=9; j++) {
String s=k.replaceAll( "[^ "+j+ "] ", " ");
if(s.length()==2) ok=true;
}
if(ok) System.out.println(i+ "* "+i+ "= "+i*i);
i++;
}
}
}