Advertisement
advictoriam

Untitled

Jan 8th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    Reads a string and counts all vowels contained in that string.
  5.    Vowels are A E I O U a e i o u.
  6.  
  7.    Input: the value of s, a string
  8.    Output: the number of all the vowels in s
  9. */
  10. public class CountVowels
  11. {
  12.    public static void main(String[] args)
  13.    {      
  14.       Scanner in = new Scanner(System.in);
  15.       String s = in.nextLine();
  16.  
  17.       int count = 0;
  18.       String vowels = "aeiouAEIOU";
  19.       for(int i = 0; i < s.length(); i++)
  20.       {
  21.          if(vowels.indexOf(s.charAt(i)) != -1){count++;}
  22.       }    
  23.  
  24.  
  25.  
  26.       System.out.println(count);
  27.    }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement