Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Midterm2
  3. {
  4.    public static void main (String[] args)
  5.    {
  6.       String phrase;
  7.       int vowels = 0;
  8.       int consonants = 0;
  9.       int position = 0;
  10.       char ch;
  11.      
  12.       Scanner input = new Scanner(System.in);
  13.       phrase = input.nextLine();
  14.       phrase = phrase.toLowerCase();
  15.      
  16.       for (position = 0 ; position < phrase.length(); position++)
  17.       {
  18.          ch = phrase.charAt(position);
  19.          if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
  20.          {
  21.             vowels++;
  22.          }
  23.          else
  24.          {
  25.             consonants++;
  26.          }          
  27.       }
  28.      
  29.       System.out.println(phrase + " has " + vowels + " vowels and " + consonants + " consonants.");
  30.    }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement