package Maths;/*** A number is said to be an Automorphic, if it is present in the last digit(s) of its square.* Example- Let the number be 25, its square is 625.* Since, 25(The input number) is present in the last two digits of its square(625),* it is an Automorphic Number.*/import java.io.*;public class AutomorphicNumber{//returns True if the number is a Automorphic number and False if it is not an Automorphic numberpublic static boolean isAutomorphic(int n){int m, c, r, p, k; c = 0;/** m = Temporary variable to store a copy of the number entered by the user.* n = The number entered by the user* c = Count the digits of the number entered by user.* p = To calculate the square of the number.* k = Support variable to count the digits of the number*/double s;m = n;p = m * m; //Calculating square of the numberdo{k = n / 10;c = c + 1; //Counting the digits of the number entered by user.n = k;}while(n != 0);s = Math.pow(10, c);r = p %(int)s;if(m == r) //Checking if the original number entered is present at the end of the square{return true;}else{return false;}}/** Method to check if number is Automorphic Number or Not* 1) Input - Enter a Number: 25* Output - It is an Automorphic Number.* 2) Input - Enter a Number: 7* Output - It is not an Automorphic Number.*/public static void main(String args[]) throws IOException{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));System.out.println("Enter a Number: ");int n=Integer.parseInt(br.readLine());if(isAutomorphic(n)){System.out.println("It is an Automorphic Number.");}else{System.out.println("It is not an Automorphic Number.");}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。