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

Output:

vowel-consonant-program-java

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