Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- Reads a string and counts all vowels contained in that string.
- Vowels are A E I O U a e i o u.
- Input: the value of s, a string
- Output: the number of all the vowels in s
- */
- public class CountVowels
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- String s = in.nextLine();
- int count = 0;
- String vowels = "aeiouAEIOU";
- for(int i = 0; i < s.length(); i++)
- {
- if(vowels.indexOf(s.charAt(i)) != -1){count++;}
- }
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement