-
Notifications
You must be signed in to change notification settings - Fork 5
/
KeywordOrNot.java
30 lines (29 loc) · 965 Bytes
/
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
/* 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.*;
public class KeywordOrNot {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] keywords = {"break", "case", "continue", "default", "defer", "else", "for", "func",
"goto", "if", "map", "range","return", "struct", "type", "var"};
String str = sc.nextLine();
int c=0;
for (int i = 0; i < keywords.length; i++) {
if(keywords[i].equalsIgnoreCase(str))
{
System.out.println("Keyword");
break;
}
else{
c++;
}
}
if(c==keywords.length)
{
System.out.println("Not a keyword");
}
}
}