-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeywordCount.java
More file actions
32 lines (31 loc) · 1.21 KB
/
KeywordCount.java
File metadata and controls
32 lines (31 loc) · 1.21 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
import java.util.Scanner;
public class KeywordCount {
public static void main(String[] args) {
int ifCount = 0, elseCount = 0, gotoCount = 0, whileCount = 0, forCount = 0, doCount = 0;
String a;
Scanner scan = new Scanner(System.in);
System.out.println("Enter a character stream: ");
do {
a = scan.next();
if (a.equals("if")) {
ifCount++;
} else if (a.equals("else")) {
elseCount++;
} else if (a.equals("goto")) {
gotoCount++;
} else if (a.equals("while")) {
whileCount++;
} else if (a.equals("for")) {
forCount++;
} else if (a.equals("do")) {
doCount++;
}
} while (!a.equals("*"));
System.out.println("Total 'if' found: " + ifCount);
System.out.println("Total 'else' found: " + elseCount);
System.out.println("Total 'goto' found: " + gotoCount);
System.out.println("Total 'while' found: " + whileCount);
System.out.println("Total 'for' found: " + forCount);
System.out.println("Total 'do' found: " + doCount);
}
}