I am writing a program in Java that is supposed to give an output like this:
- vowels = 8
- upper = 2
- digits = 5
- whitespace = 6
- vowel i occurs the most = 4
My code compiles and I was successful with everything except determining which vowel occurs the most.
I am not sure what I should do, first count how many times an individual vowel (like just "a") occurs (as opposed to how many total vowels occur in the string). After I find the total of each individual vowels, I am not sure what to use to determine the vowel with the maximum value. Once I am able to get these two steps, I then am not exactly sure how to properly output. I would prefer to accomplish this with an if statement however, I don't know if that is possible or not.
Any help/tips will be greatly appreciated, here is the code I have written:
// which vowel occurs the most
if (ch == 'a')
vowelA++;
else if (ch == 'e')
vowelE++;
else if (ch == 'i')
vowelI++;
else if (ch == 'o')
vowelO++;
else if (ch == 'u')
vowelU++;
if (vowelA > vowelE && vowelA > vowelI && vowelA > vowelO && vowelA > vowelU)
{
maxVowels = vowelA;
}
}
// OUTPUT
System.out.println("vowel" + " " + "occurs the most = " + maxVowels);
}
}