Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

Program Discussion :: Basics
Home > Programs > Basics

7. Write a program to to count number of vowels and consonants in a string.

Answer:

import java.io.*;
class q5vowels
{
    public static void main(String args[]) throws IOException
    {
        String str;
        int vowels = 0, digits = 0, blanks = 0;
        char ch;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        System.out.print("Enter a String : ");
        str = br.readLine();

        for(int i = 0; i < str.length(); i++ )
        {
            ch = str.charAt(i);

            if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || 
            ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U')
                vowels++ ;
            else if(Character.isDigit(ch))
                digits++ ;
            else if(Character.isWhitespace(ch))
                blanks++ ;
        }

        System.out.println("Vowels : "+ vowels);
        System.out.println("Digits : "+ digits);
        System.out.println("Blanks : "+ blanks);
    }
}

Post Your Answer Here:

Name *
Email

rai said:Sat, April 22, 2017, 11:17:13 am

Language:

package IBM.String;
import java.util.Scanner;

public class NumberOfVowelsAndConsonants {
    public static void main(String args[]){
        int vowel=0,consonant=0;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the String");
        String s=sc.nextLine();
        
        char arr[]=s.toLowerCase().toCharArray();
        
        for(int i=0;i<arr.length;i++){
            char ch=arr[i];
            if(Character.isLetter(ch)){
                if(ch=='a' || ch=='e' || ch=='i' || ch=='o' ||ch=='u'){
                    vowel  ;
                }else{
                    consonant  ;
                }
            }
        }
        System.out.print("Number of vowels: "+ vowel +" And Consonat: "+ consonant);
    }
    
}

Post Your Reply Here:



Monika said:Sun, June 11, 2017, 1:13:39 am

Language:

<!DOCTYPE html>
<html>
<body>
<?php
function Vowels() {
    
// input string
    
$arr ="what is your name";                                         
    echo  
"Input string is :" $arr."<br/>";
    
// initialising an empty elements for vowels and consonants
     
$vowel=0$consonents=0;                                                         
    
$arrlength=strlen($arr); 
    
// loop for reading the input array    
    
for($x=0$x$arrlength$x++)                                                   
    {
        
// comparing each character with vowels
        
if( ($arr[$x]=="a")||($arr[$x]=="e")||($arr[$x]=="i")||($arr[$x]=="o")||($arr[$x]=="u"))                    
        {
            
// for repeating the loop and skipping the below statement
            
$vowel++;                                                                       
        }
        else
        {
            
$consonents++;
        }
    }
        
// printing vowels
          
echo   "No of vowels is:  "$vowel."<br/>";                                
          echo   
"No of consonents is:  "$consonents;    
          }
Vowels();
?>  
</body>
</html>

Post Your Reply Here:



ranjan singh said:Thu, June 15, 2017, 11:43:11 am

Language:

import java.io.*;
class q5vowels
{
    public static void main(String args[]) throws IOException
    {
        String str;
        int vowels = 0, digits = 0, blanks = 0;
        char ch;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        System.out.print("Enter a String : ");
        str = br.readLine();

        for(int i = 0; i < str.length(); i++ )
        {
            ch = str.charAt(i);

            if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || 
            ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U')
                vowels++ ;
            else if(Character.isDigit(ch))
                digits++ ;
            else if(Character.isWhitespace(ch))
                blanks++ ;
        }

        System.out.println("Vowels : "+ vowels);
        System.out.println("Digits : "+ digits);
        System.out.println("Blanks : "+ blanks);
    }
}

Post Your Reply Here:



Kanika said:Thu, July 6, 2017, 9:00:45 pm

Language:

#include <stdio.h>

int main()
{
    char line[150];
    int i, vowels, consonants;

    vowels =  consonants  = 0;

    printf("Enter a line of string: ");
    scanf("%[^\n]", line);

    for(i=0; line[i]!='\0'; ++i)
    {
        if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
           line[i]=='o' || line[i]=='u' || line[i]=='A' ||
           line[i]=='E' || line[i]=='I' || line[i]=='O' ||
           line[i]=='U')
        {
            ++vowels;
        }
        else 
        {
            ++consonants;
        }
        
    }

    printf("Vowels: %d",vowels);
    printf("\nConsonants: %d",consonants);
       return 0;
}

Post Your Reply Here:



Neha said:Thu, July 6, 2017, 9:00:45 pm

Language:

#include <iostream>
using namespace std;

int main()
{
    char line[150];
    int vowels, consonants;

    vowels =  consonants =  0;

    cout << "Enter a line of string: ";
    cin.getline(line, 150);
    for(int i = 0; line[i]!='\0'; ++i)
    {
        if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
           line[i]=='o' || line[i]=='u' || line[i]=='A' ||
           line[i]=='E' || line[i]=='I' || line[i]=='O' ||
           line[i]=='U')
        {
            ++vowels;
        }
        else 
        {
            ++consonants;
        }
      

    cout << "Vowels: " << vowels << endl;
    cout << "Consonants: " << consonants << endl;
       return 0;
    }

Post Your Reply Here: