Search This Blog

Thursday, 21 July 2016

Create a class which ask the user to enter a sentence, and it should display count of each vowel type in the sentence. The program should continue till user enters a word “quit”. Display the total count of each vowel for all sentences.

import java.util.Scanner;

public class Vowel
 {

    public static void main(String[] args)
    {
        int c=0,v=0;
        String s;
        Scanner in =new Scanner(System.in);
        System.out.println("Enter String :");
        s = in.nextLine();
        s = s.toLowerCase();
        for(int i = 0 ;i<s.length();i++)
        {
            char ch = s.charAt(i);
            if (ch == 'a' || ch == 'e' || ch == 'i' ||
                                        ch == 'o' || ch == 'u'){
                                v++;
            }
            else if(ch == ' '){
               
            }
            else if (Character.isDigit(s.charAt(i)))
            {
             
            }
         
            else
                c++;
        }
        System.out.println("Vowels are "+v+" and consonants are "+c);
    }
}


output:
Enter string:
Hello World
Vowels are 3 and consonants are 7.

1 comment:

  1. this program counts vowels and consonants only .. where is the "quit" logic ??

    ReplyDelete