Computer Applications
Write a program in java 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.
Sample Input:
The goat will eat wheat
Sample Output:
OA
EA
EA
Count of vowel pairs: 3
Java
Java String Handling
64 Likes
Answer
import java.util.Scanner;
public class KboatVowelPairs
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the string: ");
String str = in.nextLine();
str = str.toUpperCase();
str += " ";
String word = "";
int count = 0;
int len = str.length();
for (int i = 0; i < str.length() - 1; i++) {
char ch1 = str.charAt(i);
char ch2 = str.charAt(i + 1);
if ((ch1 == 'A' || ch1 == 'E' || ch1 == 'I'|| ch1 == 'O'|| ch1 == 'U') &&
(ch2 == 'A' || ch2 == 'E' || ch2 == 'I'|| ch2 == 'O'|| ch2 == 'U')) {
System.out.println("" + ch1 + ch2);
count++;
}
}
System.out.println("Count of vowel pairs: " + count);
}
}Output

Answered By
27 Likes