Computer Science, asked by Cniyogi, 8 months ago

menu driven program to check wheather the the number is automorphic number or not

Answers

Answered by BRAINLYBOOSTER12
9

____________________________

Java Program to check for Automorphic Number (Way - 1)

____________________________

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.");

}

}

____________________________

Java Program to check for Automorphic Number (Way - 2)

____________________________

import java.util.Scanner;

public class AutomorphicNumber {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

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

int input = scanner.nextInt();

int square = input * input;

String inputAsString = input + "";

String squareAsString = square + "";

if (squareAsString.endsWith(inputAsString)) {

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

} else {

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

}

}

}

Answered by shirisha1981
0

Answer:Java Program to check for Automorphic Number (Way - 1)

____________________________

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.");

}

}

____________________________

Java Program to check for Automorphic Number (Way - 2)

____________________________

import java.util.Scanner;

public class AutomorphicNumber {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

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

int input = scanner.nextInt();

int square = input * input;

String inputAsString = input + "";

String squareAsString = square + "";

if (squareAsString.endsWith(inputAsString)) {

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

} else {

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

}

}

}

Similar questions