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
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
Related Questions
Which of the following returns a String?
- length()
- charAt(int)
- replace(char, char)
- indexOf(String)
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));
Write a program in Java to enter any sentence. Also ask the user to enter a word. Print the number of times the word entered is present in the sentence. If the word is not present in the sentence, then print an appropriate message.