-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeywordOrNot.java
43 lines (27 loc) · 1.06 KB
/
KeywordOrNot.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
35
36
37
38
39
40
41
42
43
/* Find a taken String is a keyword or not
* Note :
* "break", "case", "continue", "default", "defer", "else", "for", "func", "goto", "if", "map", "range","return",
"struct", "type", "var" --- these are the keywords
*/
import java.util.Scanner;
public class KeywordOrNot {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter input");
String in = sc.nextLine();
String[] keywords = {"break","null", "case", "continue", "default", "defer", "else", "for", "func", "goto", "if", "map", "range","return",
"struct", "type", "var"};
int next = 0;
for (int i = 0; i < keywords.length; i++) {
if (keywords[i].equalsIgnoreCase(in)) {
System.out.println("keyword");
break;
} else {
next++;
}
}
if(next == keywords.length){
System.out.println("Not a Keyword");
}
}
}