We are uploading our contents, please refresh app.
Java Premium

Write A Program In Java Accept A Number From The User And Check Whether It Is A Automorphic Number Or Not using impure(non-return) function.

An Automorphic number is a number whose square ends with the same digits as the original number. 

E.g – 25, 76, 376 etc.

Steps to Check Automorphic Number :
  1. Take a number as input (num).
  2. Square the number (sqr).
  3. Count the number of digits of (num) using while loop (c).
  4. Compare the last (c) digits of (sqr) with the (num).
  5. If they are equal then the number is Automorphic else not.
Program:
import java.util.*; 
public class Automorphic_imp_fun 
{
    public void fun(int n)
    {
    int c=0,sqr=1,temp,lastSquareDigits;
    sqr = n*n;
        temp=n;
        while(temp>0)
        {
            c++;
            temp=temp/10;
        }
        lastSquareDigits=(int)(sqr%(Math.pow(10,c)));
        if(n == lastSquareDigits)
        {
        System.out.println("Automorphic number");
        }
        else
        System.out.println("Not an Automorphic number");
    }
     public static void main(String args[])
      {
       int no;
        Scanner sc= new Scanner(System.in);
        System.out.println("Enter a number");
        no= sc.nextInt();
        Automorphic_imp_fun obj=new Automorphic_imp_fun ();
        obj.fun(no);
    }
}
Output:
Enter a number
5
Automorphic number
 
Enter a number
12
Not an Automorphic number

Online user

Download our android app Download App Submit your query
x

Get Updates On

Java & Premium Programs

Java Solved & Questions

Java Coding easy to use

Proper Coding

Straight Into Your INBOX!

We are going to send you our resources for free. To collect your copy at first, join our mailing list. We are promising not to bother you by sending useless information. So don't miss any updates, stay connected!