forked from Midway91/HactoberFest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.java
34 lines (26 loc) · 957 Bytes
/
Calculator.java
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
import java.util.Scanner;
public class MirrorInverse {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = scanner.nextInt();
if (isMirrorInverse(number)) {
System.out.println(number + " is a mirror-inverse number.");
} else {
System.out.println(number + " is not a mirror-inverse number.");
}
scanner.close();
}
// Function to check if a number is a mirror-inverse number
static boolean isMirrorInverse(int number) {
String numStr = String.valueOf(number);
for (int i = 0; i < numStr.length(); i++) {
int digit = Character.getNumericValue(numStr.charAt(i));
int mirrorPosition = numStr.length() - 1 - i;
if (digit != mirrorPosition) {
return false;
}
}
return true;
}
}