Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Counting vowels
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**if a string is added the program counts the number
of vowels in it**/





import java.util.*;

public class CountingVowels {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int sum = 0;
char[] vowels = {'a', 'e', 'i', 'o', 'u'};
int[] counts = new int[5];

System.out.print("What word would you like to use? ");
String word = sc.nextLine().toLowerCase();

for (int i = 0; i < word.length(); i++) {
char current = word.charAt(i);
for (int j = 0; j < vowels.length; j++) {
if (current == vowels[j]) {
sum++;
counts[j]++;
}
}
}

System.out.println("Total amount of vowels: " + sum);
System.out.println("Amount of As: " + counts[0]);
System.out.println("Amount of Es: " + counts[1]);
System.out.println("Amount of Is: " + counts[2]);
System.out.println("Amount of Os: " + counts[3]);
System.out.println("Amount of Us: " + counts[4]);

}

}