Computer Science, asked by achinta01, 1 year ago

WAP in java to check a number is automorphic no. or not.​


amannishad0512p5zxh6: hii
amannishad0512p5zxh6: i will tell

Answers

Answered by qwtiger
3

Answer:

According to mathematics, a number whose square contains  same digits as the number itself  is known as Automorphic Number. For example, 5^2 = 25, 6^2 = 36, 76^2 = 5776, and so 5, 6, 76  are all automorphic numbers.

import java.util.Scanner;

public class Test {

   public static void main(String args[])

      {

       Scanner sc = new Scanner(System.in);

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

       int num = sc.nextInt();

       int sq_num = num*num;  

 

       String str_num = Integer.toString(num);  

       String square = Integer.toString(sq_num);  

 

       if(square.endsWith(str_num))  

           System.out.println("Automorphic Number.");

       else

           System.out.println("Not an Automorphic Number.");

   }

}

Answered by lenovoideapadanishka
11

import java.util.*;

class automorphic  

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int c=0,m;

System.out.println("enter a no.");

int n=sc.nextInt();

int x=n;

while(x!=0)

{

x=x/10;

c++;

}

double p=(int)(Math.pow(10,c));

m=n*n;

if(m%p==n)

System.out.println("automorphic");

else

System.out.println("not automorphic");

}

}

Similar questions