ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2024 ICSE Computer Science Specimen Paper



Share with a Friend

Solved 2024 ICSE Computer Science Specimen Paper

Class 10 - ICSE Computer Science Solved Specimen Papers

Count the Vowels Program - ICSE 2024 Computer Science Specimen Paper

Question 5

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