import java.util.Scanner;
class llet
{
String s;
void abc()
{
Scanner sc=new Scanner(System.in);
System.out.println("ENTER ANY LETTER");
s=sc.nextLine();
switch (s)
{
case a:s="VOWEL";
break;
case A:s="VOWEL";
break;
case e:s="VOWEL";
break;
case E:s="VOWEL";
break;
case i:s="VOWEL";
break;
case I:s="VOWEL";
break;
case o:s="VOWEL";
break;
case O:s="VOWEL";
break;
case u:s="VOWEL";
break;
case U:s="VOWEL";
break;
default:s="CONSONANT";
}
}
void show()
{
System.out.println("THE LETTER YOU ENTERED IS "+s);
}
}
plz explain what is wrong in this program with the solution
Answers
Answered by
2
The mistake is : WHAT IS A,E,I,O,U??? You have to write them as 'a' 'e' 'i' 'o' 'u' , See your mistake below↓
Better to write the statement
case a:s="VOWEL";
break;
And such other statements in the program as
Corrected statement
case 'a':
S.....O......println(vowel)
And at last if the letter which the user entered is not a vowel ,it will print in this way
"the letter you have entered is b" It will not specify whether it is a consonant or vowel...
********Hope this helps**********
Better to write the statement
case a:s="VOWEL";
break;
And such other statements in the program as
Corrected statement
case 'a':
S.....O......println(vowel)
And at last if the letter which the user entered is not a vowel ,it will print in this way
"the letter you have entered is b" It will not specify whether it is a consonant or vowel...
********Hope this helps**********
Ellen1Dean2:
S...o....println means System.out.println("vowel")
Similar questions