AUTOMORPHIC NUMBER
AUTOMORPHIC NUMBER:
An automorphic number is a number whose square ends in the same digits as the number itself.
Examples of automorphic numbers : 5, 6 and 76
/*Java program to find given number is automophic number or not*/
import java.util.*;
class AutomorphicNumber
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number : "); // Inputting the number
int n = sc.nextInt();
int sq = n*n; // Finding the square
String num = Integer.toString(n); // Converting the number to String
String square = Integer.toString(sq); // Converting the square to String
if(square.endsWith(num)) // If the square ends with the number then it is Automorphic
System.out.print(n+" is an Automorphic Number.");
else
System.out.print(n+" is not an Automorphic Number.");
}
}
OUTPUT:
Enter a Number : 5
5 is an Automorphic Number.
Enter a Number : 9
9 is not an Automorphic Number.
No comments:
Post a Comment