Computer Science, asked by angela1001, 1 year ago

Test whether a number is automorphic or not using JAVA....

Attachments:

Answers

Answered by GoshtHunter
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");

    }

  }

}

Similar questions