Para cualquier carácter dado, debemos verificar si es una vocal o una consonante. Como sabemos, las vocales son ‘a’, ‘e’, ’i’, ‘o’, ‘u’ y todos los demás caracteres (es decir, ‘b’, ‘c’, ‘d’, ‘f’….. ) son consonantes.
Java
// java program to check whether input // character is a vowel or consonant import java.io.*; public class geek { // Function to find whether an input // character is vowel or not static void Vowel_Or_Consonant(char y) { if (y == 'a' || y == 'e' || y == 'i' || y == 'o' || y == 'u') System.out.println("It is a Vowel."); else System.out.println("It is a Consonant."); } // The Driver code static public void main(String[] args) { Vowel_Or_Consonant('b'); Vowel_Or_Consonant('u'); } }
Java
// java program to check whether input // character is a vowel or consonant import java.io.*; public class geek { // Function to find whether an input // character is vowel or not static void Vowel_Or_Consonant(char y) { if (y == 'a' || y == 'e' || y == 'i' || y == 'o' || y == 'u' || y == 'A' || y == 'E' || y == 'I' || y == 'O' || y == 'U') System.out.println("It is a Vowel."); else System.out.println("It is a Consonant."); } // The Driver code static public void main(String[] args) { Vowel_Or_Consonant('W'); Vowel_Or_Consonant('I'); } }
Java
// java program to check whether input // character is a vowel or consonant import java.io.*; class GFG { // Function to find whether an input // character is vowel or not static String isVowel(char ch) { // Make the list of vowels String str = "aeiouAEIOU"; return (str.indexOf(ch) != -1) ? "Vowel" : "Consonant"; } // Driver Code public static void main(String[] args) { System.out.println("It is a " + isVowel('a')); System.out.println("It is a " + isVowel('x')); } }
Publicación traducida automáticamente
Artículo escrito por Kanchan_Ray y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA