How to check Automorphic number in java

Checking Automorphic number





Steps to do this :-
1.take 5 integers a,b,c,d,n
2. take a value from user 
3.now store the value in a (a=n)
4. now do b=n*n now b  has the square of the given number
5.now do c=b%10 now c has the last digit of the square number
6.now do d=a%10 now d has the last digit of the given number
7. check if(c==d) then print (" the square of the number is "+c) and print " this is an automorphic number"
8. else print "this is not an automorphic number"
9.save and run


The Source  Code

import java.util.Scanner;
class au
{
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int a,b,c,d,n;
        System.out.println("enter the number");
        n=s.nextInt();
        a=n;//a has the given value
        b=n*n;// b has the square value
        c=b%10;// c has the last value of the square number
        d=a%10;// d has the last value of the given number
        if(c==d)
        {
            System.out.println("the square of "+n+" is "+b);
            System.out.println("this is an automorphic number !");

        }
        else

        {
            System.out.println("the square of "+n+" is "+b);
            System.out.println("this is not an automorphic number!");
        }

    }
}

OUTPUT

WATCH MY VIDEO

Comments

Popular Posts