SHARE
TWEET

Untitled

advictoriam Jan 8th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top