
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to Check Whether an Alphabet is Vowel or Consonant
In this article, we will understand how to check whether an alphabet is vowel or consonant. Alphabets that include 'a' 'e' 'i' 'o' 'u' are called Vowels and all other alphabets are called Consonants.
Below is a demonstration of the same −
Input
Suppose our input is −
Enter the character : i
Output
The desired output would be −
The character : i is a vowel
Algorithm
Step 1 - START Step 2 - Declare a char value namely my_input. Step 3 - Read the required values from the user/ define the values Step 4 - Using an if condition, check if the input is equal to 'a' 'e' 'I' 'o' 'u' values. If yes, its an vowel. Else it's a consonant. Step 5 - Display the result Step 6 - Stop
Example 1
Here, the input is being entered by the user based on a prompt. You can try this example live in our coding ground tool .
import java.util.Scanner; public class VowelAndConsonant { public static void main(String[] args) { char my_input; System.out.println("Required packages have been imported"); Scanner my_scanner = new Scanner(System.in); System.out.println("A reader object has been defined "); System.out.print("Enter the character : "); my_input = my_scanner.next().charAt(0); if(my_input == 'a' || my_input == 'e' || my_input == 'i' || my_input == 'o' || my_input == 'u' ) System.out.println("The character : " +my_input + " is a vowel"); else System.out.println("The character : " +my_input + " is a consonant"); } }
Output
Required packages have been imported A reader object has been defined Enter the character : i The character : i is a vowel
Example 2
Here, the integer has been previously defined, and its value is accessed and displayed on the console.
public class VowelAndConsonant { public static void main(String[] args) { char my_input = 'i'; System.out.println("The character is defined as :" +my_input); if(my_input == 'a' || my_input == 'e' || my_input == 'i' || my_input == 'o' || my_input == 'u' ) System.out.println("The character : " +my_input + " is a vowel"); else System.out.println("The character : " +my_input + " is a consonant"); } }
Output
The character is defined as :i The character : i is a vowel
- Related Articles
- Haskell Program to Check Whether an Alphabet is Vowel or Consonant
- Golang Program to Check Whether an Alphabet is Vowel or Consonant
- C++ Program to Check Whether a character is Vowel or Consonant
- Java program to find whether given character is vowel or consonant
- Java program to find whether given character is vowel or consonant using switch case
- Java Program to Check Whether a Character is Alphabet or Not
- Haskell Program to Check Whether a Character is Alphabet or Not
- C++ Program to Check Whether a Character is Alphabet or Not
- Program to find if a character is vowel or Consonant in C++
- Java program to find whether the given character is an alphabet or not
- Java Program to check whether two Strings are an anagram or not.
- Java Program to Check Whether a Number is Even or Odd
- Java Program to Check Whether a Number is Positive or Negative
- Java Program to Check Whether a Number is Prime or Not
- How to check whether a character is in the Alphabet or not in Golang?

Advertisements