- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to find whether given character is vowel or consonant using switch case
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case. To verify whether given character is a vowel read a character from the user into a variable (say ch).
Define a boolean bool variable and initialize it with false.
Define cases for character ch with vowel characters, both capital and small ('a', 'e', 'i', 'o', 'u' ) without break statements.
For all these assigns make the bool variable true.
Finally, if the value of the bool variable is true given character is a vowel else consonant
Example
import java.util.Scanner; public class VowelOrConsonantSwitch { public static void main(String args[]) { boolean bool = false; System.out.println("Enter a character :"); Scanner sc = new Scanner(System.in); char ch = sc.next().charAt(0); switch(ch) { case 'A' : case 'E' : case 'I' : case 'O' : case 'U' : case 'a' : case 'e' : case 'i' : case 'o' : case 'u' : bool = true; } if(bool == true){ System.out.println("Given character is an vowel "); }else{ System.out.println("Given character is a consonant "); } } }
Output
Enter a character : a Given character is an vowel Enter a character : l Given character is a consonant
- Related Articles
- Java program to find whether given character is vowel or consonant
- C++ Program to Check Whether a character is Vowel or Consonant
- Java Program to Check Whether an Alphabet is Vowel or Consonant
- Program to find if a character is vowel or Consonant in C++
- Haskell Program to Check Whether an Alphabet is Vowel or Consonant
- Golang Program to Check Whether an Alphabet is Vowel or Consonant
- Java program to find whether the given character is an alphabet or not
- Java Program to check whether the entered character a digit, white space, lower case or upper case character
- Java program to find whether given number is even or odd
- Java program to generate a calculator using the switch case
- Java Program to Make a Simple Calculator Using switch...case
- Java Program to Check Whether a Character is Alphabet or Not
- Java program to find whether the given string is empty or null
- C program to find the areas of geometrical figures using switch case
- Alternate vowel and consonant string in C++

Advertisements