write a program in java to check if the number entered by user is automorpic .( automorphic no. is the number which is contained in the last digit(s) of its square)
Answers
{
public static void main ( int n)
{
int i, c=o,m=n;
for (i=m ; m>0 ; m/=10)
c+=1;
if (n%1000 == n)
System.out.println(" automorphic number");
else
System.out.println (" not an automorphic no. ");
}
}
#Mark brainliest
Sample program to check whether the number entered by user is automorphic:
import java.util.Scanner;
public class Brainly
{
static void ct()
{
Scanner pt=new Scanner(System.in);
System.out.println("Enter a number that you want to check if its automorphic.");
int num=pt.nextInt();
int sqr=0, b=0, c=1;
sqr=num*num;
int d=num;
int l=num;
while(num!=0)
{
b++;
num=num/10;
}
for(int k=1;k<=b;k++)
{
c=c*10;
}
int dig=sqr%c;
if(dig==d)
{
System.out.println("Entered number is an automorphic number.");
}
else System.out.println("Entered number is not an automorphic number.");
}
}
Output:
Enter a number that you want to check if its automorphic.
5
Entered number is an automorphic number.