Automorphic Number
---------------------------
Given a number N, the task is to check whether the number
is Automorphic number or not.
A number is called Automorphic
number if and only if its square ends in the same digits as
the number itself.
Examples :
Input : N = 76
Output : Automorphic
Explanation: As 76*76 = 5776
Input : N = 25
Output : Automorphic
As 25*25 = 625
Input : N = 7
Output : Not Automorphic
As 7*7 = 49
// Source Code
import java.util.*;
public class Automorphic
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N,square,count=0,ncopy;
System.out.print("Enter a Number To Check : ");
N=in.nextInt();
square=N*N;
ncopy=N;
while(N!=0)
{
N=N/10;
count++;
}
if( square%Math.pow(10,count)==ncopy )
{
System.out.print("It is an Automorphic Number . ");
}
else
{
System.out.print("It is Not an Automorphic Number . ");
}
}
}
//Sample Input :
Enter a Number To Check : 25
// Sample Output:
It is an Automorphic Number .
//Sample Input :
Enter a Number To Check : 6
// Sample Output:
It is an Automorphic Number .
//Sample Input :
Enter a Number To Check : 9
// Sample Output:
It is Not an Automorphic Number .
//Sample Input :
Enter a Number To Check : 12
// Sample Output:
It is Not an Automorphic Number .
---------------------------
Given a number N, the task is to check whether the number
is Automorphic number or not.
A number is called Automorphic
number if and only if its square ends in the same digits as
the number itself.
Examples :
Input : N = 76
Output : Automorphic
Explanation: As 76*76 = 5776
Input : N = 25
Output : Automorphic
As 25*25 = 625
Input : N = 7
Output : Not Automorphic
As 7*7 = 49
// Source Code
import java.util.*;
public class Automorphic
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int N,square,count=0,ncopy;
System.out.print("Enter a Number To Check : ");
N=in.nextInt();
square=N*N;
ncopy=N;
while(N!=0)
{
N=N/10;
count++;
}
if( square%Math.pow(10,count)==ncopy )
{
System.out.print("It is an Automorphic Number . ");
}
else
{
System.out.print("It is Not an Automorphic Number . ");
}
}
}
//Sample Input :
Enter a Number To Check : 25
// Sample Output:
It is an Automorphic Number .
//Sample Input :
Enter a Number To Check : 6
// Sample Output:
It is an Automorphic Number .
//Sample Input :
Enter a Number To Check : 9
// Sample Output:
It is Not an Automorphic Number .
//Sample Input :
Enter a Number To Check : 12
// Sample Output:
It is Not an Automorphic Number .
0 Comments