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
Related Questions
Write the output of the following String methods:
String x= "Galaxy", y= "Games";(a) System.out.println(x.charAt(0)==y.charAt(0));
(b) System.out.println(x.compareTo(y));
Which of the following returns a String?
- length()
- charAt(int)
- replace(char, char)
- indexOf(String)
The following code to compare two strings is compiled, the following syntax error was displayed – incompatible types – int cannot be converted to boolean.
Identify the statement which has the error and write the correct statement. Give the output of the program segment.
void calculate() { String a = "KING", b = "KINGDOM"; boolean x = a.compareTo(b); System.out.println(x); }