Java program to check vowel or consonant


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

import java.util.Scanner;
class Char
{
                    public static void main(String[ ] arg)
                    {
                    int i=0;
	Scanner sc=new Scanner(System.in);
	System.out.println("Enter a character : ");
                    char ch=sc.next( ).charAt(0);	 		
                    if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
                    {
	System.out.println("Entered character "+ch+" is  Vowel"); 
                    }
                    else if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
		System.out.println("Entered character "+ch+" is Consonant");
                    else
		System.out.println("Not an alphabet");		
                    }
}

Result

java techstudy.org

     





Related Topics




Popular Posts