This is a BlueJ program which will take the upper range and will
display all the automorphic numbers starting from 1 to the specific number.
import java.io.*;
class AutoM
{
int x,i,n,no,sqn,revNum=0,digit=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void getNumber() throws Exception
{
System.out.println("Enter the upper range:");
x=Integer.parseInt(br.readLine());
for(int j=1;j<=x;j++)
{
n=j;
digit=0;
revNum=0;
no=n;
do
{
digit++;
no=no/10;
} while(no!=0);
sqn=n*n;
showR();
}
}
public void showR()
{
do
{
revNum=revNum*10+sqn%10;
sqn=sqn/10;
digit--;
if(digit==0)
break;
} while(true);
revNum=revNumerse(revNum);
if(n==revNum)
System.out.println(n+" is an Automorphic number");
}
private int revNumerse(int n)
{
int r=0;
while(n!=0)
{
r=r*10+n%10;
n=n/10;
}
return r;
}
public static void main(String args[])throws Exception
{
AutoM obj=new AutoM();
obj.getNumber();
}
}
Related Post: BlueJ Programs on Number
thanks
ReplyDelete