Topic: Counting Vowels in String Java, Counting Vowels in User Supplied String Java Program
This topic covers – How to count the number of vowels in a give string using a Java Program.
Source Code:
import java.util.Scanner; public class CountingVowels { public static void main(String args[]){ int count = 0; System.out.println("Enter a sentence :"); Scanner sc = new Scanner(System.in); String sentence = sc.nextLine(); sentence = sentence.toLowerCase(); for (int i=0 ; i<sentence.length(); i++){ char ch = sentence.charAt(i); if(ch == 'a'|| ch == 'e'|| ch == 'i' ||ch == 'o' ||ch == 'u'){ count ++; } } System.out.println("Number of vowels in the given sentence is "+count); } } //Output //Enter a sentence : //welcome //Number of vowels in the given sentence is 3
Pingback: Python Text File Program To Count Vowels | EasyCodeBook.com