-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordPhilosophyTwoOne.java
More file actions
50 lines (42 loc) · 1.51 KB
/
PasswordPhilosophyTwoOne.java
File metadata and controls
50 lines (42 loc) · 1.51 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class PasswordPhilosophyTwoOne {
public static void main(String[] args) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("passwordphilosophy.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int count = 0;
try {
String s = reader.readLine();
while (s != null) {
String[] parts = s.split(" ");
String[] limits = parts[0].split("-");
int lowerLimit = Integer.parseInt(limits[0]);
int upperLimit = Integer.parseInt(limits[1]);
char letter = parts[1].charAt(0);
int letterCount = 0;
String password = parts[2];
if (password.length() >= lowerLimit) {
for (int idx = 0; idx < password.length(); idx++) {
if (letter == password.charAt(idx)) {
letterCount++;
}
}
if (letterCount >= lowerLimit && letterCount <= upperLimit) {
count++;
}
}
s = reader.readLine();
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(count);
}
}