I need to write a program that finds all the palindrome perfect squares between two integers supplied as an input but that do not include the inputs supplied.
My program gets "killed" when you put in a large range of inputs i.e 10000 and 100000. How can i fix this please?
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);
}
}
}
This is another simple and concise way to print palindrome square numbers.
Define isPerfectSquare & isPalindrome methods as below