Check Vowel Or Consonant Using "If Condition" | Java Programs

Output:

*** Check Whether A Character Is Vowel Or Consonant ***

Enter a single character : A
"A" is a Vowel
-----------------------------------------------------------
*** Check Whether A Character Is Vowel Or Consonant ***

Enter a single character : R
"R" is a Consonant
-----------------------------------------------------------
*** Check Whether A Character Is Vowel Or Consonant ***

Enter a single character : 68
Please enter an alphabetic character!!!

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

public class VowelOrConsonantUsingIf {

    public static void main(String[] arg) {
        boolean isVowel = false;
        Scanner sc = new Scanner(System.in);
        System.out.println("*** Check Whether A Character Is Vowel Or Consonant ***" + "\n");
        System.out.print("Enter a single character : ");
        char ch = sc.next().charAt(0);
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'
                || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
            isVowel = true;
        }
        if (isVowel == true) {
            System.out.println("\"" + ch + "\"" + " is a Vowel");
        } else {
            if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
                System.out.println("\"" + ch + "\"" + " is a Consonant");
            } else {
                System.out.println("Please enter an alphabetic character!!!");
            }
        }
    }
}
Share This :

Related Post

avatar

nice article in your blog.thank you for sharing useful info.
visit
web programming tutorial
welookups

delete 29 August 2018 at 20:24



sentiment_satisfied Emoticon