char eng = jTextField1.getText().charAt(0); //if you method return a String it gets the 1st character
switch(eng){
case'a':
case'e':
case'i':
case'o':
case'u': jTextField2.setText("It is a vowel");
break;
default: jTextField2.setText("It is not a vowel");
break;
}
But better way :
char eng=jTextField1.getText().charAt(0);
ArrayList<Character> list=new ArrayList<Character>();
list.add('a');
list.add('e');
list.add('i');
list.add('o');
list.add('u');
list.add('y');
if(list.contains(eng)){
jTextField2.setText("It is a vowel");
}else{
jTextField2.setText("It is not a vowel");
}
2
solved Switch case Java error in coding [closed]