Java Question Set I – Conditional Statements in Java

2. Write a program in Java to check whether the input alphabet is a vowel or not.

Logic of the solution:

  1. Declare le of char type to store user input into it.
  2. Print a message for  the user using System.out.println and ask user for a letter
    1. Using charAt(0)  to take the 1st letter only as input even if the user writes a word.
  3. Compare the letter in the variable using the conditional statements
    1. If the input is equal to any of the vowel, then it is a Vowel otherwise it is a Consonant
  4. Print Message accordingly
import java.util.*;
class vowel
	public static void main(String [] arg)
		Scanner sc = new Scanner(;
		char le;
		System.out.println("Enter a Letter");".").charAt(0);
		if(le=='a' || le=='e' || le=='i' || le=='o' || le=='u' || le=='A' || le=='E' || le=='I' || le=='O' || le=='U')
			System.out.println(le+" is vowel");
			System.out.println(le+" is not a vowel");



Alternative logics that can be applied:

As in previous question this one can also be done using an Array, here we will store the vowels as elements of the Array and compare them with the user input one by one using if statement.

Continue to next page for another question.

0 Responses on Java Question Set I - Conditional Statements in Java|

Leave a Message

Your email address will not be published. Required fields are marked *

CommentLuv badge

Pin It on Pinterest