Check Vowel in Java


Q. Write a Java program to check a character is vowel or not

import java.util.Scanner;

public class VowelCheck {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Ask user to enter a character
        System.out.print("Enter a character: ");
        char ch = scanner.next().toLowerCase().charAt(0); // Read and convert to lowercase

        // Check if the character is a vowel
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
            System.out.println(ch + " is a vowel.");
        } else if ((ch >= 'a' && ch <= 'z')) {
            System.out.println(ch + " is a consonant.");
        } else {
            System.out.println("Invalid input! Please enter an alphabet character.");
        }

        scanner.close();
    }
}
 

Q. Write an algorithm to check a character is vowel or not

1. Start
2. Read a character and store it in ch
3. Convert ch to lowercase
4. If ch is equal to 'a', 'e', 'i', 'o', or 'u', then
→ Print "It is a vowel"
5. Else if ch is a letter from 'a' to 'z', then
→ Print "It is a consonant"
6. Else
→ Print "Invalid input"
7. End 



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.