Home Java Programming Language / Programs / Question 9
🚀 Programming Example

Question 9

👁 95 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

📌 Information & Algorithm

Question 9

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

💻 Program Code

import java.util.Scanner;

public class RAnsariVowelPair
{
    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);
    }
}
                        
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.