I was given a practice problem where I have to write a method that produces true if the inputted string is a vowel (not case-sensitive). When I submit the code, it produces an infinite loop at the second test but I have no idea what could be causing it.
I tried to mess around with the variable declaration but writing x = input.next(); instead of x = input.nextLine(); but that causes an infinite loop with the first test as well.
`public static boolean isVowel(String x) { Scanner input = new Scanner(System.in); x = input.nextLine();
// checking if the inputted string is a vowel
if ((x.equalsIgnoreCase("a")) || (x.equalsIgnoreCase("e")) || (x.equalsIgnoreCase("i")) ||
(x.equalsIgnoreCase("o")) || (x.equalsIgnoreCase("u"))) {
return true;
} else {
return false;
}
}`
Aucun commentaire:
Enregistrer un commentaire