-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlphabetChecker.java
More file actions
44 lines (36 loc) · 1.45 KB
/
AlphabetChecker.java
File metadata and controls
44 lines (36 loc) · 1.45 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class AlphabetChecker {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the path to the text file: ");
String filePath = scanner.nextLine();
try {
File file = new File(filePath);
Scanner fileScanner = new Scanner(file);
String content = "";
while (fileScanner.hasNextLine()) {
content += fileScanner.nextLine();
}
boolean containsAllLetters = containsAllAlphabetLetters(content.toUpperCase());
if (containsAllLetters) {
System.out.println("The text file contains all 26 letters of the alphabet.");
} else {
System.out.println("The text file does not contain all 26 letters of the alphabet.");
}
fileScanner.close();
} catch (FileNotFoundException e) {
System.out.println("File not found. Please make sure the file path is correct.");
}
scanner.close();
}
private static boolean containsAllAlphabetLetters(String text) {
for (char letter = 'A'; letter <= 'Z'; letter++) {
if (!text.contains(String.valueOf(letter))) {
return false;
}
}
return true;
}
}