What's Wrong? Why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's Wrong? Why?

import java.util.*; class VowelConsonant { public static void main(String args[]) { Scanner input=new Scanner(System.in); System.out.print("Enter Any Letter : "); char ch; ch= input.next().CharAt(0); if(ch=='A' || ch=='a' || ch=='E' || ch=='e' || ch=='I' || ch=='i' || ch=='O' || ch=='o' || ch=='U' || ch=='u'){ System.out.println(ch+" Is a Vowel"); }else{ System.out.println(ch+" Is a Consonant"); } } }

4th Oct 2021, 1:22 PM
Milon
Milon - avatar
4 Answers
+ 3
Yup that question totally make sense... Next time, try to be more constructive on your question. Ask a specifically and state an exact problem you have, rather than just writing "What's wrong" Regarding your question, you wrote CharAt() instead of charAt() Here is a fixed version of your code: https://code.sololearn.com/cy8C0qx08Ama/?ref=app
4th Oct 2021, 1:28 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 5
// this is another way that you could do it. Scanner input=new Scanner(System.in); char ch= input.next().CharAt(0); String v= "aeiou"; if (v.indexOf(Character.toLowerCase(ch))>=0) System.out.println(ch+" Is a Vowel"); else System.out.println(ch+" Is a Consonant");
4th Oct 2021, 2:54 PM
SoloProg
SoloProg - avatar
+ 1
Okay😶 Thanks
4th Oct 2021, 1:32 PM
Milon
Milon - avatar
+ 1
Milon , No problem buddy 👍 Happy learning!
4th Oct 2021, 1:32 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar