Test whether a number is automorphic or not using JAVA....
Attachments:
Answers
Answered by
0
import java.util.Scanner;
public class AutomorphicNumber {
public static void main(String args[]) {
//Input number to be tested
System.out.print("Enter any number :");
Scanner scanner = new Scanner(System.in);
int inputNo = scanner.nextInt();
//Convert the input number and its square to string
String inputNoStr = String.valueOf(inputNo);
String squaredrStr = String.valueOf(inputNo * inputNo);
//Check if the squared no's string ends with input no
//directly library of endsWith of java. Lang
if (squaredrStr.endsWith(inputNoStr)) {
System.out.println(inputNo + " is an automorphic number");
} else {
System.out.println(inputNo + " is NOT an automorphic number");
}
}
}
public class AutomorphicNumber {
public static void main(String args[]) {
//Input number to be tested
System.out.print("Enter any number :");
Scanner scanner = new Scanner(System.in);
int inputNo = scanner.nextInt();
//Convert the input number and its square to string
String inputNoStr = String.valueOf(inputNo);
String squaredrStr = String.valueOf(inputNo * inputNo);
//Check if the squared no's string ends with input no
//directly library of endsWith of java. Lang
if (squaredrStr.endsWith(inputNoStr)) {
System.out.println(inputNo + " is an automorphic number");
} else {
System.out.println(inputNo + " is NOT an automorphic number");
}
}
}
Similar questions
Social Sciences,
7 months ago
Math,
7 months ago
Math,
7 months ago
Social Sciences,
1 year ago
English,
1 year ago