Computer Science, asked by kgautam16847, 9 months ago

Program 8.14
Write a program in Java to determine if an entered alphabet is a vowel or a consonant.​

Answers

Answered by yashagarwal140
1

public class VowelConsonant {

   public static void main(String[] args) {

       char ch = 'i';

       if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )

           System.out.println(ch + " is vowel");

       else

           System.out.println(ch + " is consonant");

   }

}

Answered by SƬᏗᏒᏇᏗƦƦᎥᎧƦ
49

/* VowelOrConsonantWithSwitch.java */

import java.util.Scanner ;

public class VowelOrConsonantWithSwitch

{

public static void main (String args [ ] )

{

Scanner scan = new Scanner (System.in);

System.out.println("Enter a character:");

char myChar = scan.next ( ) .charAt (0);

if ((myChar >= 'a' && myChar <= 'z' ) || ( myChar >= 'A' && myChar <= 'Z' )

else

System.out.print( myChar + " is not an alphabet" ) ;

scan.close( ) ;

}

static void CheckVowelOrConsonant ( char ch)

{

switch (ch)

{

case'a' : case 'e' : case 'i' : case 'o' : case 'u'

case 'A': case 'E' : case 'I' : case 'O' : case 'U'

System.out.print("Character"+ ch " is a Vowel") ;

break;

default :

System.out.println( " Character"+ch" is a Constant") ;

}

}

}

Output Output

Enter a character : 8 Enter a character: u

8 is not a alphabet. Character u is a vowel

Output.

Enter a character:T. Enter a character:G

Character T is a constant. Character G is a consonant

Similar questions