Computer Science, asked by BrainlyPromoter, 1 year ago

Write a Java program that prompts the user to enter a number and checks whether the entered number is automorphic or not.

After writing the complete, kindly explain the main logic of each step.

Answers

Answered by siddhartharao77
47

Automorphic number:

A number whose square ends in the same digits as the number itself is considered as Automorphic number.  

Sample Program for Automorphic number:

import java.util.*;

class Brainly

{

public static void main(String args[])

{

int a,b,c,d,n;

Scanner demo = new Scanner(System.in);

System.out.print("Enter a number: ");

n = demo.nextInt();

a = n * n;

b = 0;

c = 1;

d = n;

while(n!=0)

{

b++;

n = n/10;

}

for(int i = 1; i<=b;i++)

c = c * 10;

if(a%c==d)

System.out.println("Given number is automorphic");

else

System.out.println("Given number is not automorphic");

}

}

Output:

Enter a number : 15

Given number is not automorphic

Enter a number : 5

Given number is automorphic

Enter a number : 7

Given number is not automorphic.

Hope this helps!

Attachments:
Answered by sofia147
0
Class Automorphic{ void number (int n) {int, a, s, c = 1; a= n; s = n*n; while ( n! = 0; { c = c*10; n = n/10;} if ( s=℅ c ==a).... . And ℅ means percent OK. ✌✌ my next rank is virtuoso and I have five brainliest answer so plz plz plz mark me as brainliest and plz plz follow me✌✌✌✌
Similar questions