-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVowelChecker.java
More file actions
35 lines (26 loc) · 979 Bytes
/
VowelChecker.java
File metadata and controls
35 lines (26 loc) · 979 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
import java.util.Scanner;
public class VowelChecker {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String inputString = scanner.nextLine();
int vowelCount = 0;
boolean hasVowels = false;
// Convert string to lowercase for case-insensitive check
inputString = inputString.toLowerCase();
for (char character : inputString.toCharArray()) {
if (character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u') {
vowelCount++;
hasVowels = true;
}
}
String message;
if (hasVowels) {
message = "The string contains " + vowelCount + " vowel(s).";
} else {
message = "The string does not contain any vowels.";
}
System.out.println(message);
scanner.close();
}
}