-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJava.java
25 lines (22 loc) · 863 Bytes
/
Java.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
import java.io.*;
import java.util.ArrayList;
class Java7SegmentDisplays {
public static void main(String[] args) {
final var longest = new ArrayList<String>();
final var invalid = "(?i).*[gkmqvwxzio].*";
var maxlen = 0;
try (final var br = new BufferedReader(new FileReader("words.txt"))) {
while (br.ready()) {
String word = br.readLine();
if (word.length() == maxlen && !word.matches(invalid)) {
longest.add(word);
} else if (word.length() > maxlen && !word.matches(invalid)) {
longest.clear();
longest.add(word);
maxlen = word.length();
}
}
} catch (IOException e) { e.printStackTrace(); }
longest.forEach(System.out::println);
}
}