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
Define a class to accept a string and convert the same to uppercase, create and display the new string by replacing each vowel by immediate next character and every consonant by the previous character. The other characters remain the same.
Example:
Input : #IMAGINATION@2024
Output : #JLBFJMBSJPM@2024Which of the following returns a String?
- length()
- charAt(int)
- replace(char, char)
- indexOf(String)
Define a class to accept the gmail id and check for its validity.
A gmail id is valid only if it has:
→ @
→ .(dot)
→ gmail
→ com
Example:
icse2024@gmail.com
is a valid gmail idConsider the following program segment in which the statements are jumbled, choose the correct order of statements to check if a given word is Palindrome or not.
boolean palin(String w) { boolean isPalin; w = w.toUpperCase(); int l = w.length(); isPalin = false; // Stmt (1) for (int i = 0; i < l / 2; i++) { char c1 = w.charAt(i), c2 = w.charAt(l - 1 - i); // Stmt (2) if (c1 != c2) { break; // Stmt (3) isPalin = true; // Stmt (4) } } return isPalin; }