Today I present to you a program that:
- Identifies vowels and their total number
- Prints each vowel's numeric value
- Adds the numeric value of each vowel found
- Prints which letters are NOT vowels
If you want to check out the rules from where I got the project, here you go.
package countVowels;
import java.util.Scanner;
public class vowelCounter {
static Scanner scan = new Scanner(System.in);
static String word;
char vowel;
int valueOfVowel;
int totalValueOfVowels = 0;
int iterations = 0;
int i;
public void counter() {
for(i = 0; i < word.length();) {
vowel = word.charAt(i);
if (vowel == 'a' || vowel == 'e' || vowel == 'i' || vowel == 'o' || vowel == 'u') {
valueOfVowel = Character.getNumericValue(vowel);
iterations++;
totalValueOfVowels += valueOfVowel;
i++;
System.out.println("The vowel is: " + vowel + " ");
System.out.println("Character value of " + vowel + ": " + valueOfVowel);
System.out.println("------------------------");
}else {
System.out.println("This isn't a vowel: " + word.charAt(i));
System.out.println("------------------------");
i++;
}
}
while(i == word.length()) {
System.out.println("The number of vowels is: " + iterations);
System.out.println("The total sum of all vowels is: " + totalValueOfVowels);
break;
}
}
public static void main(String[] args) {
word = scan.next();
scan.close();
new vowelCounter().counter();
}
}