Hey there, I need some advice on how to complete some code. The code needs to take an inputted string from the user, then print out the number of vowels in the string. The challenge here is that I'm only allowed to use nested if statements (so no chained if statements or compound conditions). Here's what I have:
public static void problem() { Scanner keyboard = new Scanner(System.in); System.out.println("Enter a string and I will tell you the number of vowels that appear."); String input = keyboard.nextLine(); String lowerCaseInput = input.toLowerCase(); int stringLength = input.length(); int numberOfOccurancesOfVowels = 0; for (int count = 0; count < stringLength; count++) { } System.out.println("There are " + numberOfOccurancesOfVowels + " vowels in " + input + "."); }
I don't understand how using nested if statements can complete the task. I know what they are, and how to use them, but I have no idea on how to apply them to this situation. They should be placed within the loop, but what should the conditions be? I was thinking of putting in the following if's within the loop, but it would be both time consuming and extremely long-winded. I'm 100% certain that there is a simpler way.
Thank you for any help you provide. Please don't say anything along the lines of "check out The Java™ Tutorials" or "go buy a Java textbook and read it." I would like some actually helpful information from people who have a better grasp of what to do than I. Again, thanks for reading and any advice.if ((lowerCaseInput.charAt(count) != 'b')) { if ((lowerCaseInput.charAt(count) != 'c')) { if ((lowerCaseInput.charAt(count) != 'every other char except for a,e,i,o,u')) { numberOfOccurancesOfVowels++; } } }