TOP CONTENT
Lavi Thakur  

Write a java program to read a positive integer from the console and find out whether it is an automorphic number or not.

Automorphic numbers are those which are found on the extreme right side of their square.For example : –

5=25

6=36

25=625

Hence,5,6,25 are Automorphic numbers.

import java.util.*;

public class Automorphic

{

public static void main (String args [])

{

int num,s;

int i,j,m,n,f;

int [] a=new int [10];

int [] b=new int [5];

BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

System.out.println(“Enter number =”);

String x = input.readLine();

num = Integer.parseInt(x);

s = num*num;

i=0;

j=0;

f=0;

while(num !=0)

{

b[i] = num % 10;

num /=10;

++i;

}

while(s !=0)

{

a[j] = s % 10;

s /=10;

++j;

}

for(n = 0,m = 0, n < i;n++,m++)

{

if(a[m] ! = b[n])

f = 1;

}

if (f==0)

System.out.println(“Number is automorphic”);

else

System.out.println(“Number is not automorphic”);

}

}

In the above post we have discussed a java program of how to check whether a number is automorphic or not.For more such related posts or programing,gaming,technology related posts regularly visit our blog.

THANK YOU!!! FOR VISITING OUR BLOG.

Leave A Comment