Home Tutorial Java Core How to Check Automorphic Number using Java Program

 
 

How to Check Automorphic Number using Java Program
Posted on: November 10, 2009 at 12:00 AM
In this Java tutorial section, you will learn how to check whether the number entered by the user is automorphic number or not.

How to Check Automorphic Number using Java Program

Automorphic numbers are the numbers whose square ends with the number itself or you can say it is a number whose square ends with the given integer. For example,5 is an automorphic number as the square of 5 is 25 and its square consists of number 5 in the end. Similarly 6 is an automorphic number as the square of 6 is 36 and its square consists of number 6 at the end. Here we are going to check whether the number entered by the user is automorphic or not.

Here is the code:

import java.math.*;
import java.util.*;

class AutomorphicNumber {
	static int d = 10;

	public static void main(String args[]) {
		System.out.print("Enter any number :");
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		if (d >= n) {
			if ((n * n) % d == n) {
				System.out.println("Automorphic Number");
			} else {
				System.out.println("Not Automorphic Number");
			}
		} else if (d <= n) {
			d = d * 10;
			if ((n * n) % d == n) {
				System.out.println("Automorphic Number");
			} else {
				System.out.println("not an automorphic number");
			}
		}
	}
}
Output
Enter any number :56
Not an automorphic number

Related Tags for How to Check Automorphic Number using Java Program:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.