-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountVowelsDigits.java
42 lines (34 loc) · 1.08 KB
/
CountVowelsDigits.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
public class CountVowelsDigits {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = scanner.nextLine();
int vowelCount = countVowels(input);
int digitCount = countDigits(input);
System.out.println("Number of vowels: " + vowelCount);
System.out.println("Number of digits: " + digitCount);
scanner.close();
}
private static int countVowels(String input) {
int count = 0;
for (char c : input.toCharArray()) {
if (isVowel(c)) {
count++;
}
}
return count;
}
private static boolean isVowel(char c) {
return "aeiouAEIOU".indexOf(c) != -1;
}
private static int countDigits(String input) {
int count = 0;
for (char c : input.toCharArray()) {
if (Character.isDigit(c)) {
count++;
}
}
return count;
}
}