Automorphic Number

In mathematics, an automorphic number is a number whose square "ends" in the same digits as the number itself. For example, 52 = 25, 62 = 36, 762 = 5776, and 8906252 = 793212890625, so 5, 6, 76 and 890625 are all automorphic numbers.

 import java.util.*;

class automorphic

{//class automorphic opens

    public static void main(String[]args)

    {//main method opens

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter a no");

        int n=sc.nextInt();//variable n to accept the no

        int sq=n*n;//variable sq to store the square of the no

        int c=0,k=n;//variable c to store the no of digits,variable k to store the no

        while(k>0)

        {

          c=c+1;

          k=k/10;

        }

        int l=sq%(int)Math.pow(10,c);//varible l to extract the no from the last part of the square

        if(n==l)

        System.out.println("It is an automorphic no");

        else

        System.out.println("It is not an automorphic no");

    }//main method closes

}//class closes


No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...