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 "); } }
0 comments:
Post a Comment