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.
Create your own Web Browser Source Code
Programming Quiz App for Android (Offline Version)
Modern Login and Register screen UI design
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.