-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetterClassifier.java
More file actions
49 lines (43 loc) · 1.7 KB
/
LetterClassifier.java
File metadata and controls
49 lines (43 loc) · 1.7 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
/*
Rahim Siddiq
Apr 21 2023
Vowel or consonant
*/
import java.util.Scanner;
public class LetterClassifier
{
public static void main(String[] args)
{
// Program variables
char letterChoice;
// Title of program and description of program function to user
System.out.println(" ====================================================================");
System.out.println(" ========================= Vowel Or Consonat ========================");
System.out.println(" ====================================================================");
System.out.println(" Program determines whether a letter is a vowel or consonant ");
System.out.println(" --------------------------------------------------------------------");
System.out.println();
// Scanner object for input
Scanner input = new Scanner(System.in);
// User input
System.out.print(" Please enter an alphabetic letter, then press [Enter]: ");
letterChoice = input.next().charAt(0);
// Convert input to lower case for comparison
letterChoice = Character.toLowerCase(letterChoice);
// Check if letter is entered
if (!Character.isLetter(letterChoice))
{
System.out.println(" Invalid input.");
}
else if (letterChoice == 'a' || letterChoice == 'e' || letterChoice == 'i' || letterChoice == 'o' || letterChoice == 'u')
{
System.out.println(" " + letterChoice + " is a vowel.");
}
else
{
System.out.println(" " + letterChoice + " is a consonant.");
}
// Close the Scanner to prevent resource leak
input.close();
}
}