I have this problem for homework (I'm being honest, not trying to hide it at least)
And I'm having problems figuring out how to do it.
Given the following declarations : String phrase = " WazzUp ? - Who's On FIRST ??? - IDUNNO"; Write the necessary code to
count the number of vowels in the string and print appropriate message to the screen.
Here's the code I have so far:
String phrase = " WazzUp ? - Who's On FIRST ??? - IDUNNO";
int i, length, vowels = 0;
String j;
length = phrase.length();
for (i = 0; i < length; i++)
{
j = phrase.substring(i, i++);
System.out.println(j);
if (j.equalsIgnoreCase("a") == true)
vowels++;
else if (j.equalsIgnoreCase("e") == true)
vowels++;
else if (j.equalsIgnoreCase("i") == true)
vowels++;
else if (j.equalsIgnoreCase("o") == true)
vowels++;
else if (j.equalsIgnoreCase("u") == true)
vowels++;
}
System.out.println("Number of vowels: " + vowels);
However, when I run it it just makes a bunch of blank lines. Can anyone help?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…