Java Code Example: advanced switch-case statement

This example checks whether a character entered is a vowel or a consonant. The user is first prompted to enter a letter. The input variable is passed to the checkCharacter() function to check the type of the letter.

import java.util.Scanner;

class VowelOrConsonant {
    public static void checkCharacter(char input) {
        boolean isVowel = false;
        switch (input) {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U':
                isVowel = true;
        if (isVowel) {
            System.out.println(input + " is a vowel");
        } else {
            if ((input >= 'a' && input <= 'z') || (input >= 'A' && input <= 'Z'))
                System.out.println(input + " is a consonant");

    public static void main(String[] args) {
        Scanner scan = new Scanner(;
        char input;

        System.out.println("Please enter a character: ");
        input =;

Output 1
Please enter a character: A
A is a vowel
Output 2
Please enter a character: d
d is a consonant