C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Count the Vowels Program - Java Programs

Define a class to accept a string and convert it into uppercase. Count and display the number of vowels in it.

import java.util.Scanner; class Vowels{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("Enter a string: "); String s = in.nextLine().toUpperCase(); int count = 0; for(int i = 0; i < s.length(); i++){ char ch = s.charAt(i); if("AEIOU".indexOf(ch) >= 0) count++; } System.out.println(s); System.out.println("Number of vowels: " + count); } }

Output

 
 OUTPUT 1: 
Enter a string: THIS IS A JAVA PROGRAM
THIS IS A JAVA PROGRAM
Number of vowels: 7

 OUTPUT 2: 
Enter a string: ultra info technologies
ULTRA INFO TECHNOLOGIES
Number of vowels: 9