हिंदी

Count the total number of vowels in a string.

Advertisements
Advertisements

प्रश्न

Count the total number of vowels in a string.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
class clString
{
    public void main() 
    {
        Scanner sc = new Scanner(System.in);
        String ts = "";
        int c = 0, j;
        System.out.print("Enter a string: ");
        ts = sc.nextLine();
        for(j = 0; j<= ts.length() - 1; j++)               
        {
            char ch = ts.charAt(j);
            if(ch='a' || ch='e' || ch='i' || ch='o' ||
            ch='u' || ch='A' || ch='E' || ch='I' ||
            ch='O′ || ch='U' )
            {
                c++; 
            }
        }        
        System.out.print(" The number of vowels in " + ts + " is: " + c);
    }
}

Output:

Enter the string : Leonardo DA VINCI

The number of vowels in Leonardo DA VINCI is : 7

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 11: Programs Overall - String Handling [पृष्ठ २५२]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 11 Programs Overall
String Handling | Q 1. | पृष्ठ २५२
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×