How to Find Vowels in a String

In this problem we will learn how to find the Number of Vowels in a string. After receiving input from user convert it to lower or upper case and then in a loop define the condition of vowels finding . Another variables count will be update whenever a vowels find in the loop . 

Source Code


package com.ancodingpoint.www;
import java.util.Scanner;

public class Find_Vowels
{
 public static void main(String[] args)
 {
            Scanner input = new Scanner (System.in);
            String story ="";
            int count =0;
            System.out.println(" Enter Your Story Here .....! ");
            story = input.nextLine();
            story = story.toLowerCase();
            for (int i = 0; i<story.length();i++)
            {
                if (story.charAt(i)=='a')
                {
                    count++;
                }
              if (story.charAt(i)=='e')
                {
                    count++;
                }
              if (story.charAt(i)=='i')
                {
                    count++;
                }
            if (story.charAt(i)=='o')
                {
                    count++;
                }
            if (story.charAt(i)=='u')
                {
                    count++;
                }
            }
            
 System.out.println(" Your Story Contain :" + count + " Vowels ");
       } }

Output of the Program

Java String Programming




Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment