Q:

Java program to check vowel or consonant

belongs to collection: Simple Formula Based Java Programs

0

Java program to check vowel or consonant

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

answer using switch statement

import java.util.Scanner;
public class boom2 {

	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
        System.out.println("enter the letter to check its vowel or not:");
        String letter=in.next();
        char letterC=letter.charAt(0);
switch(letterC)
      {
          case 'a':
          case 'e':
          case 'o':
          case 'i':
          case 'u':
          case 'A':
          case 'E':
          case 'O':
          case 'I':
          case 'U':
              System.out.println("vowel");
              break;
          default:
              System.out.println("not vowel");
      }
}
}

need an explanation for this answer? contact us directly to get an explanation for this answer
need an explanation for this answer? contact us directly to get an explanation for this answer

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..

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:

Enter a character : 

o

Entered character o is  Vowel

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (2)

Java program to sum of N numbers... >>
<< Java program to calculate average marks...