-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVowelCount.java
More file actions
39 lines (31 loc) · 887 Bytes
/
VowelCount.java
File metadata and controls
39 lines (31 loc) · 887 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
36
37
38
39
package examples;
import java.util.Scanner;
public class VowelCount {
public static void main(String[] args) {
int vowelCount = 0;
System.out.print("Enter String - ");
Scanner sc = new Scanner(System.in);
String data = sc.nextLine().trim();
String dataUC = data.toUpperCase();
long inTime = System.currentTimeMillis();
for (int i = 0; i < data.length(); i++) {
switch (dataUC.charAt(i)) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
System.out.print(data.charAt(i) + "(" + i + ") ");
vowelCount++;
break;
default:
break;
}
}
long outTime = System.currentTimeMillis();
System.out.println("\nTotal Time taken - " + (outTime - inTime) + " ms");
System.out.println("Total Vowel Count - " + vowelCount);
System.out.println("* Replacement - " + data.replaceAll("[aeiouAEIOU]", "*").toString());
sc.close();
}
}