Programming Examples

Java program to input an integer and check whether it is an automorphic trimorphic or automorphic number or no


Write a program to input an integer and check whether it is an automorphic, trimorphic or tri-automorphic number or not. A number n is said to be automorphic, if its square ends in n. For instance 5 is automorphic, because 52= 25, which ends in 5, 25 is automorphic, because 252=625, which ends in 25. A number n is called trimorphic if n3 ends in n. For example 493, = 117649, is trimorphic. A number n is called tri-automorphic if 3n2 ends in n; for example 667 is tri-automorphic because 3 × 6672, = 1334667, ends in 667.

Solution

import java.util.*;
class Automorphic
{
	public static void main(String arr[])
	{
		Scanner sc=new Scanner(System.in);
		int i,d,a,c=0;
		System.out.println("Enter an integer:");
		a=sc.nextInt();
		for(i=a;i>0;i=i/10)
		{
		c++;
		}
		if((a*a)%(int)Math.pow(10,c)==a)
			System.out.println("Automorphic Number");
		else if((a*a*a)%(int)Math.pow(10,c)==a)
			System.out.println("Trimorphic Number");
		else if((3*a*a)%(int)Math.pow(10,c)==a)
			System.out.println("Tri-Automorphic Number");
		else
			System.out.println("Not any type of Automorphic Number");
	}
}
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad