In the following question, we are supposed to ask the user for character input and check if the input is a vowel or not using Switch Case construct.

Algorithm:

  1. Enter and Store User Input.
  2. Duplicate the input and store it.
  3. Change the Case of the duplicate for lesser comparison and uniformity.
  4. Pass the input through Switch-Case construct.
  5. Check for Vowel.
  6. Print the Result accordingly.
/* Program to check if entered character is vowel or not using Switch Case*/
import java.util.*;
class SwitchVowel
{
public static void main()
{
Scanner inp=new Scanner(System.in);
System.out.print("\n Enter Character: ");
char c=((inp.nextLine()).charAt(0));
char z=Character.toUpperCase(c); //Changing Value to UpperCase for uniformity.

switch(z) //Checking Vowel Character using Switch Case
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': System.out.println(c+" is a Vowel.");
break;

default: System.out.println(c+" is a Non-Vowel Character.");
}

}
}

Output:

Enter Character: X
X is a Non-Vowel Character.

 Enter Character: u
u is a Vowel.

 Enter Character: 5
5 is a Non-Vowel Character.

Related Posts:

[yuzo_views]











CopyRight © 2019

CopyRight © 2019