Java Online Compiler
Example: CheckVowelConsonantIfElse in Java
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// CheckVowelConsonantIfElse import java.util.Scanner; // Main class containing the entry point of the program public class Main { public static void main(String[] args) { // Step 1: Create a Scanner object to read input from the console Scanner scanner = new Scanner(System.in); // Step 2: Prompt the user to enter a character System.out.print("Enter a character: "); char ch = scanner.next().charAt(0); // Read the first character of the input // Step 3: Check if the character is an alphabet if (!Character.isLetter(ch)) { System.out.println(ch + " is not an alphabet."); } else { // Step 4: Check if the character is a vowel (case-insensitive) if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') { System.out.println(ch + " is a Vowel."); } else { // Step 5: If it's an alphabet but not a vowel, it's a consonant System.out.println(ch + " is a Consonant."); } } // Step 6: Close the scanner scanner.close(); } }
Output
Clear
ADVERTISEMENTS