Write a Java-program to check the given character is vowel or consonant( Character must be small letter)

Write a Java-program to check the given character is vowel or consonant( Character must be small letter)

Program
public class Main
{
	public static void main(String args[])
	{
        char ch='r';
        if(ch>='a' && ch<='z')
        {
            if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
            {
                System.out.println("Vowel");
            }
            else
            {
                System.out.println("Consonant");
            }
        }
        else
        {
           System.out.println("Please Enter Small Letter"); 
        }
	}
}	

Output:

Consonant

Using CommandLine Arguments
public class Main
{
	public static void main(String args[])
	{
        char ch;
        ch=args[0].charAt(0);
        if(ch>='a' && ch<='z')
        {
            if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
            {
                System.out.println("Vowel");
            }
            else
            {
                System.out.println("Consonant");
            }
        }
        else
        {
           System.out.println("Please Enter Small Letter"); 
        }
	}
}	

Output:

Consonant

Using Scanner Class
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
        char ch;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter character: ");
        ch=s.next().charAt(0);
        if(ch>='a' && ch<='z')
        {
            if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
            {
                System.out.println("Vowel");
            }
            else
            {
                System.out.println("Consonant");
            }
        }
        else
        {
           System.out.println("Please Enter Small Letter"); 
        }
	}
}	

Output:

Enter character : r
Consonant





More Questions


37 . Write a Java-program to print Max Number amoung the three numners using else if
38 . Write a Java-program to check the given character is vowel or consonant( Character must be small letter)
39 . Write a Java-program to check Odd or Even number program using nested if condition(value must be positive)
40 . Write a Java-program to check Odd or Even number using switch
41 . Write a Java-program to check Vowel or Consonant using switch
42 . Write a Java-program to display 1 to 10 values using for loop
43 . Write a Java-program to display 10 to 1 values using for loop
44 . Write a Java-program to display 1 to n values using for loop
45 . Write a Java-program to display display Even Numbers using for loop
46 . Write a Java-program to display Even Number or Odd Number based on the N value using for loop
47 . Write a Java-program to display Even Number or Odd Number based on the N value using single for loop