ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2020 ICSE Computer Science Paper



Share with a Friend

Solved 2020 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Pair of Vowels Program - ICSE 2020 Computer Science

Write a program to input a string and convert it into uppercase and print the pair of vowels and number of pair of vowels occurring in the string.
Example:
INPUT:
“BEAUTIFUL BEAUTIES”
OUTPUT:
Pair of vowels: EA, AU, EA, AU, IE
No. of pair of vowels: 5

import java.util.Scanner; public class KboatVowelPair { static boolean isVowel(char ch) { ch = Character.toUpperCase(ch); if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') return true; return false; } public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.println("Enter the sentence:"); String str = in.nextLine(); str = str.toUpperCase(); int count = 0; System.out.print("Pair of vowels: "); for (int i = 0; i < str.length() - 1; i++) { if (isVowel(str.charAt(i)) && isVowel(str.charAt(i + 1))) { count++; System.out.print(str.charAt(i)); System.out.print(str.charAt(i+1) + " "); } } System.out.print("\nNo. of pair of vowels: " + count); } }

Output

 
 OUTPUT : 
 Enter the sentence:
BEAUTIFUL BEAUTIES
Pair of vowels: EA AU EA AU IE 
No. of pair of vowels: 5