import java.io.*;
public class Kaprekar2010_2
{
public static void main(String args[])throws Exception
{
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the lower limit:");
int p=Integer.parseInt(stdin.readLine());
System.out.print("Enter the upper limit:");
int q=Integer.parseInt(stdin.readLine());
if(q<p)
System.out.println("INVALID INPUT");
else
{
int count=0;
System.out.println("THE KAPREKAR NUMBERS ARE:-");
for(int i=p;i<=q;i++) //checking between the limits
{
String s=""+i;
int d=s.length();
int sq=i*i;
int rd=(int)(sq%(Math.pow(10,d))); //finding right-hand piece
int ld=(int)(sq/(Math.pow(10,d))); //finding left-hand piece
if(i==(rd+ld))
{
if(count==0)
System.out.print(i);
else
System.out.print(","+i);
count++;
}
}
System.out.println();
System.out.println("FREQUENCY OF KAPREKAR NUMBERS IS:"+count);
}
}
}

No comments:
Post a Comment