forked from anish-mishr/specialNumbers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomorphicNumber.java
More file actions
33 lines (29 loc) · 1.17 KB
/
Copy pathAutomorphicNumber.java
File metadata and controls
33 lines (29 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package specialNumbers;
/**
* @author Anish
*
*
*/
public class AutomorphicNumber {
/* Automorphic Number is a number in which the square of the number ends with the same number.
* for example 5 is Automorphic Number
* 5 => 5^2 => 25 and last digit of 25 is 5 which is same as number
*/
public static void automorphicNumber(int num) { // Static Method
int sqr, lstDigitNum, lstDigitSqr;
sqr = num * num; // Holds Square of Num
lstDigitSqr = sqr % 10; // holds last digit of Square
lstDigitNum = num % 10; //holds lst digit of Num
if(lstDigitNum == lstDigitSqr) //Check Condition for Automorphic Number
System.out.println(">> "+ num +" is Automorphic Number"); // IF YES prints Automorphic Number
else
System.out.println(">> "+ num +" is NOT Automorphic Number"); // IF NO prints NOT Automorphic Number
}
// MAIN METHOD
public static void main(String[] args) {
// Input is another public class having getNumber STATIC Method and a return type of INTEGER
System.out.println(" Find A Number is Automorphic Number or NOT");
int num = Input.getNumber(); // gets the NUM
automorphicNumber(num); // Static method to check number is Automorphic Number or NOT
}
}