-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountVowels.java
More file actions
60 lines (51 loc) · 1.65 KB
/
Copy pathCountVowels.java
File metadata and controls
60 lines (51 loc) · 1.65 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
50
51
52
53
54
55
56
57
58
59
60
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package countvowels;
import javax.swing.JOptionPane;
/**
*
* @author Adam
*/
public class CountVowels {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String input = JOptionPane.showInputDialog(null, "Please enter a word or sentence:");
int totalVowels = VowelCount(input);
JOptionPane.showMessageDialog(null, "The total number of vowels you entered was: " + totalVowels);
}
public static int VowelCount(String input){
String checkVowel = null;
int vowelCount = 0;
//char vowelChar;
StringBuilder input1 = new StringBuilder();
input1.append(input);
for(int i=0;i<input1.length();i++){
Character vowelChar = input1.charAt(i);
checkVowel = vowelChar.toString();
System.out.println(checkVowel);
switch (checkVowel) {
case "a":
vowelCount++;
break;
case "e":
vowelCount++;
break;
case "i":
vowelCount++;
break;
case "o":
vowelCount++;
break;
case "u":
vowelCount++;
break;
}
}
return vowelCount;
}
}