Computer Science, asked by Cniyogi, 1 year ago

menu driven program to check automorphic number or not

Answers

Answered by Anonymous
0

ram ram ....

your programme be like

The programme can be written as follows.

import java.io.*; public class MenuPrimeAutomorphicNumber { public static void main(String args[])throws IOException { int i,ch,a,no,m,f=1,c=0,p; InputStreamReader in=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(in); System.out.println("1. For Prime number"); System.out.println("2. For Automorphic number"); System.out.print("Enter your choice:"); ch=Integer.parseInt(br.readLine()); switch(ch) { case 1: System.out.print("Enter number to check prime:"); no=Integer.parseInt(br.readLine()); for(i=2;i<no;i++) { if(no%i==0) { f=0; break; } } if(f==1) System.out.print("Prime number"); else System.out.print("Not Prime number"); break; case 2: System.out.print("Enter number to check Automorphic:"); no=Integer.parseInt(br.readLine()); m=no; while(m!=0) { m/=10; c++; } p=(int)Math.pow(10,c-1); a=no%p; if(no==a*a) System.out.println("Automorphic number");else System.out.println("Not Automorphic number"); break; default: System.out.println("Wrong choice"); } }} Output: 1. For Prime number 2. For Automorphic number Enter your choice:1 Enter number to check prime:5 Prime number 1. For Prime number 2. For Automorphic number Enter your choice:2 Enter number to check Automorphic: 25 Automorphic number...

hope it helps...

follow me ❤️⏪...

Answered by BRAINLYBOOSTER12
3

import java.util.*;

class Automorphic

{

public static void main(String args[]) throws Exception

{

Scanner sc = new Scanner(System.in);

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

int n = sc.nextInt();

int sq = n*n;

int c = 0, copy = n;

// While loop for counting the number of digits in the number

while(copy > 0)

{

c++;

copy = copy/10;

}

int end = sq % (int)Math.pow(10,c);

if(n == end) // If the square ends with the number then it is Automorphic

System.out.print(n+" is an Automorphic Number.");

else

System.out.print(n+" is not an Automorphic Number.");

}

}

Similar questions