AJ Java Programs
Program 3 :
Automorphic Number
A Number is said to be Automorphic if its square contains digits same as number.For Example:- 25 is Automorphic Number Since its Square 625 contains the original number 25.
Syntax
import java.io.*;class automorphic
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,sq,c=1,d=0;
System.out.println("Enter a Number");
n=Integer.parseInt(br.readLine());
sq=n*n;
int n1=n;
while(n!=0)
{
d=n%10;
c=c*10;
n=n/10;
}
if(sq%c==n1)
{
System.out.println(n1+" is Automorphic number");
}
else
{
System.out.println(n1+" is not Automorphic number");
}
}
}
// tested ok
try values 25,36,5,
Comments
Post a Comment