FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 149   



Following program shows you how to take a character and tells its vowel or consonant.
In this program we get a character from user and shows it's vowel or consonant using if condition

import java.util.Scanner;

public class Basic5 {

    public static void main(String[] args) {

        System.out.println("Enter a character:");

        Scanner in = new Scanner(System.in);
        char input = in.next().charAt(0);

        if (input == 'a' || input == 'A' || input == 'e' || input == 'E' || input == 'i' || input == 'I' || input == 'o'
                || input == 'O' || input == 'u' || input == 'U') {

            System.out.println("Its a vowel");

        } else if ((input >= 'a' && input <= 'z') || (input >= 'A' && input <= 'Z')) {

            System.out.println("Its a consonant");

        } else {

            System.out.println("Invalid input please enter an alphabet");

        }
    }

}

Output:

Example1:

Enter a character:
a
Its a vowel

Example2:

Enter a character:
y
Its a consonant

Example3:

Enter a character:
-2
Invalid input please enter an alphabet



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News