Created
December 30, 2019 12:41
Java Snippet to count number of vowels in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class CountVowel | |
{ | |
public static void main(String s[]) | |
{ | |
Scanner sc = new Scanner(System.in); | |
int count = 0; | |
char ch; | |
System.out.println("Enter The String To Count No. Of Vowels : "); | |
String str = sc.nextLine(); | |
for(int i=0;i<str.length();i++) | |
{ | |
ch = str.charAt(i); | |
if((ch == 'a') || (ch == 'e') || (ch == 'i') || (ch == 'o') || (ch == 'u')) | |
{ | |
count++; | |
} | |
} | |
System.out.println("The no of vowels in given string is : " + count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment