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

 
 

Share on Google+Share on Google+
How to Check Automorphic Number using Java Program
Posted on: November 10, 2009 at 12:00 AM
Advertisement
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
Advertisement

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


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 10, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com