-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomorphicNumber.java
More file actions
42 lines (34 loc) · 1.22 KB
/
Copy pathAutomorphicNumber.java
File metadata and controls
42 lines (34 loc) · 1.22 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
34
35
36
37
38
39
40
41
42
/* An automorphic number is a number whose square ends in the same digits as the
* number itself.
* for example: 5, 6, 25 are automorphic numbers.
* 5 * 5 = 25 --> last digit is 5
* 6 * 6 = 36 --> last digit is 6
* 25 * 25 = 625 --> last digit is 25
*/
import java.util.*;
class AutomorphicNumber {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter a number to check either It is automorphic or not : ");
int number = input.nextInt();
int inputHolder = number;
int square = number * number; // Finding square
System.out.println("Square of number is : " + square);
int divisor = 10;
boolean equal = false; // for checking equality
while( number > 0 ){
int remainder = square % divisor;
if(number == remainder){
equal = true;
break;
}
number = number / 10;
divisor = divisor * 10;
}
if(equal == true){
System.out.println(inputHolder +" is an Automorphic number.");
}else {
System.out.println(inputHolder +" is NOT an Automorphic number.");
}
}
}