Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i am having a hard time with this code... I am trying to turn the \"if...else\"

ID: 3656212 • Letter: I

Question

i am having a hard time with this code... I am trying to turn the "if...else" into a loop but I am not quite sure how to do it. [code] public static void main(String[] args) { char charr[]={'a','e','i','o','u'}; Scanner input=new Scanner(System.in); System.out.println("Enter a character: "); char ch=input.next().charAt(0); if((charr[0]==ch)||(charr[1]==ch)||(charr[2]==ch)||(charr[3]==ch)||(charr[4]==ch)) { System.out.println("Entered character is vowel"); } else { System.out.println("Entered character is not a lowercase vowel"); } }[code/]

Explanation / Answer

public static void main(String[] args) { char char[]={'a','e','i','o','u'}; Scanner input=new Scanner(System.in); System.out.println("Enter a character: "); char ch=input.next().charAt(0); for( ;((charr[0]==ch)||(charr[1]==ch)||(charr[2]==ch)||(charr[3]==ch)||(charr[4]==ch)); ) { System.out.println("Entered character is vowel"); break;} for( ;((charr[0]!=ch)||(charr[1]!=ch)||(charr[2]!=ch)||(charr[3]!=ch)||(charr[4]!=ch)); ) { System.out.println("Entered character is not a lowercase vowel"); } }