Automorphic Number
- Categories Java
Accept a number from user and print if given number is Automorphic number or not.
Automorphic number: A Automorphic number is a number which is contained in the last digit(s) of its square.
For example: 25 in 625
Watch our video on how to solve any Number Program – Click Here
import java.util.Scanner;
public class AutomorphicNumber
{
public static void main(){
Scanner sc = new Scanner(System.in);
int n;
System.out.println("Enter any number:");
n= sc.nextInt();
int m = n;
int flag = 0, q = n * n;
while (n != 0) {
int d = n%10;
int d1 = q%10;
if (d != d1)
flag = 1;
n = n / 10;
q = q / 10;
}
if ( flag == 0)
System.out.println ("yes");
else
System.out.println ("no");
}
}
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021