If the user enters a string: hello there
he should output
Hello has 2 vowels
There has 3 consonants.
I know this is pretty simple code, but I get too many ideas and get confused. I need to have 2 methods for numberofVowels and capitalizeWord, and both return the result
I get an error message and I'm still trying to figure it out to make money on the account after I started counting vowels
import java.util.Scanner;
public class Hwk9
{
public static void main (String args[])
{
Scanner stdin = new Scanner(System.in);
String string1;
System.out.println("Enter a string");
string1 = stdin.nextLine();
string1 = string1.toLowerCase();
}
public static int numberVowels(String string1)
{
int count = 0;
int vowels = 0;
int consonants = 0;
for (int i = 0; i < string1.length(); i++)
{
char ch = string1.charAt(i);
if (ch == 'a' || ch == 'e' || ch == 'i' ||
ch == 'o' || ch == 'u')
{
vowels++;
}
else
{
consonants++;
}
}
}
}
source
share