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
Complete Chat Application Using Firebase Database
Login and Register using Firebase Realtime Database
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.