-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem3.java
More file actions
42 lines (37 loc) · 926 Bytes
/
Problem3.java
File metadata and controls
42 lines (37 loc) · 926 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
38
39
40
41
42
import java.util.Scanner;
public class Problem3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
String letter = new String();
int count = 0;
int i = 0;
System.out.print("Enter a text: ");
String text = in.nextLine();
while(true) {
System.out.print("Enter a letter: ");
letter = in.nextLine();
if(!letter.isEmpty()) {
if(letter.trim().length() == 1) {
char ch[] = text.toCharArray();
for(i = 0; i < text.length(); i++) {
if(ch[i] == letter.trim().charAt(0))
count++;
}
System.out.print("There are " + count +
" "+ letter.trim().charAt(0) + "'s in the text.");
break;
}
else{
System.out.println("You must enter a single letter.");
continue;
}
}
else {
System.out.println("You must enter a single letter.");
continue;
}
}
in.close();
}
}