-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrobo.java
More file actions
39 lines (28 loc) · 1001 Bytes
/
strobo.java
File metadata and controls
39 lines (28 loc) · 1001 Bytes
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
import java.util.HashMap;
import java.util.Scanner;
public class strobo {
static boolean strobonum(String s ){
HashMap<Character , Character> h = new HashMap<>();
h.put('0', '0');
h.put('1', '1');
h.put('8', '8');
h.put('9', '6');
h.put('6', '9');
int n = s.length();
for(int i= 0, j=n-1 ; i<n ;i++ , j--){
char left = s.charAt(i);
char right = s.charAt(j);
char m = h.getOrDefault(left,'-');
if(m=='-')return false;
if(m!=right)return false;
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
sc.close();
if(strobonum(s)){System.out.println( s +" is a strobo grammatic number");}
else { System.out.println(s + " is not a strobo grammatic number");}
}
}