Q:

Write a java program to check vowel or consonant

0

Write a 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

import java.util.Scanner;
public class JavaExcercise {
 
  public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        System.out.print("plz enter a letter: ");
        String s = in.next();
        char c = s.charAt(0);
        if(c=='a' || c=='e'||c=='i'||c=='o'||c=='u'||c=='U'||c=='I'||c=='O' ||c=='E' ||c=='A'){
            System.out.println("letter is vowel");
        }
        else
            System.out.println("consonant");
    }
}

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;
public class JavaExcercise {
 
 
  public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
 
        System.out.print("Enter any alphabet: ");
        String input = in.next().toLowerCase();
 
        boolean uppercase = input.charAt(0) >= 65 && input.charAt(0) <= 90;
        boolean lowercase = input.charAt(0) >= 97 && input.charAt(0) <= 122;
        boolean vowels = input.equals("a") || input.equals("e") || input.equals("i")
                || input.equals("o") || input.equals("u");
 
        if (input.length() > 1)
        {
            System.out.println("Error. Not a single character.");
        }
        else if (!(uppercase || lowercase))
        {
            System.out.println("Error. Not a letter. Enter uppercase or lowercase letter.");
        }
        else if (vowels)
        {
            System.out.println("Input letter is Vowel");
        }
        else
        {
            System.out.println("Input letter is Consonant");
        }
    }
}

Result:

Enter any alphabet: A

Input letter is Vowel

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

total answers (2)

Write a Java program to display the cube of the nu... >>
<< Write a program in Java to display the first 5 nat...