Java - Check whether an alphabet is vowel or consonant.
example_1.java
/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset App from PlayStore to learn coding*/
/*Example 1: Check whether an alphabet is vowel or consonant using if..else statement*/
public class example_1 {
public static void main(String[] args) {
char ch = 'i'; // initilize a char type variable with value 'i'
/* In english vowel characters are 'aeiou'. Now compare ch variable with all vowel characters using OR Conditional Operator*/
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
System.out.println(ch + " is vowel");
else
System.out.println(ch + " is consonant");
}
}
// OUTPUT
// 'i' is vowel
example_2.java
/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset App from PlayStore to learn coding*/
/*Example 2: Check whether an alphabet is vowel or consonant using switch statement*/
public class example_2{
public static void main(String[] args) {
char ch = 'l';
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println(ch + " is vowel");
break;
default:
System.out.println(ch + " is consonant");
}
}
}
// OUTPUT
/* / is consonant */
Projects with Source Code + Video Tutorials
You can download our Java and Android Studio Projects with Source Code and Video Tutorials.
![Modern-Splash-Screen-with-Animations---01](https://learnoset.com/Learnoset/Projects/SplashScreen1/splash_screen.png)
Modern Splash Screen with Animations - 01
![Online-Quiz-Application-using-Firebase-Realtime-Database-Source-Code](https://learnoset.com/Learnoset/Projects/OnlineQuizApp/online_quiz_app.jpg)
Online Quiz Application using Firebase Realtime Database Source Code
![Simple-Music-Player-App-(Version-2)-for-Android-(Offline-Version)](https://learnoset.com/Learnoset/Projects/MusicPlayer2/music_player2.png)
Simple Music Player App (Version 2) for Android (Offline Version)
If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com
Follow us to learn Coding and get in touch with new Technologies.