我需要编写一个程序来查找作为输入提供但不包括提供的输入的两个整数之间的所有回文完美平方。
当您输入大量输入(即 10000 和 100000)时,我的程序会被“杀死”。请问我该如何解决这个问题?
import static java.lang.Math.sqrt;
import java.util.Scanner;
public class PalinPerfect {
public static void main(String[] args){
Scanner user_input = new Scanner(System.in);
String start_point;
System.out.print("Enter start point N:\n");
start_point = user_input.next();
int start = Integer.parseInt(start_point);
String finish_point;
System.out.print("Enter ending point M:\n");
finish_point = user_input.next();
int finish = Integer.parseInt(finish_point);
System.out.print( "The palindromic perfect squares are as follows:\n");
for(int i=start; i <=finish; i++){
int a,n1,n2=0;
n1=i;
for(a = 0; a <= i; a++) {
if (a==Math.sqrt(n1)) {
n2=n1;
}
}
int number = n2;
int reversedNumber = 0;
int temp=0;
while(number > 0){
temp = number % 10;
number = number / 10;
reversedNumber = reversedNumber * 10 + temp;
}
if(n1 == reversedNumber)
System.out.println(n1);
}
}
}