Padd Solutions

Converted by Falcon Hive

import java.util.Scanner;

public class LetterCounter
{
    public static void main (String[] args)
    {
        Scanner scan = new Scanner (System.in);
        String phrase;
        int space=1;
        char check;
       
        System.out.println ("Enter a phrase, c'mon. DO IT!");
        phrase = scan.nextLine();
       
        int vowels = 1;
        int length = phrase.length() - 1;
        int others = -1;
        int punctuation = 0;
        for (int i = 0; i <= length; i++)
        {
            if (phrase.charAt (i) == 'a' || phrase.charAt (i) == 'e' || phrase.charAt (i) == 'i' || phrase.charAt (i) == 'o' || phrase.charAt (i) == 'u')
            {
                vowels++;
            }
           
            else if (phrase.charAt (i) == ' ')
            {
                space++;
            }
           
            else if (phrase.charAt (i) == '?' || phrase.charAt (i) == '!' || phrase.charAt (i) == '.' || phrase.charAt (i) == ',')
            {
                punctuation++;
            }
           
            else
            {
                others++;
            }
        }
       
        System.out.println ("Your phrase is made up of "+space+" words.");  
        System.out.println ("There are "+others+" consonants in your phrase.");       
        System.out.println ("There are "+vowels+" vowels in your phrase.");
    }
}

(0) Comments

Post a Comment