Computer Science, asked by vasanthij97, 1 year ago

Write a program to check if the given character is a vowel or consonant.
this is a java program.any1 answer plz.....fast!!



nashabhi612: Hi sam
nashabhi612: Good morning

Answers

Answered by kishorkeepsmiling
6

public class VowelConsonant {

   public static void main(String[] args) {

   //Enter any character  

   char ch = 'f';

       if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){

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

       }

       else {

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

       }

   }

}


kishorkeepsmiling: If input 'a', 'e, 'i', 'o', 'u', "A", "E", "I", "O", "U" except anything then output is "[your input] is constant"
kishorkeepsmiling: :)
kishorkeepsmiling: If you want to do something if 'a' or 'A' then use switch case.
kishorkeepsmiling: but for differentiate Vowel and Consonant, it's not required.
Answered by Praneeth331
4
#include <stdio.h> int main() { char c; int isLowercaseVowel, isUppercaseVowel; printf("Enter an alphabet: "); scanf("%c",&c); // evaluates to 1 (true) if c is a lowercase vowel isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); // evaluates to 1 (true) if c is an uppercase vowel isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); // evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true if (isLowercaseVowel || isUppercaseVowel) printf("%c is a vowel.", c); else printf("%c is a consonant.", c); return 0; }
Similar questions