如果用户输入一个字符串:  hello there
它应该输出
Hello has 2 vowels
There has 3 consonants.
我知道这是一个相当简单的代码,但我得到了太多想法并且感到困惑。我需要一个来确保我有 2 个方法用于 numberofVowels 和 capitalizeWord 并且都返回一个结果
我遇到了一个错误,在我开始计算元音之后,我仍然想弄清楚是否要大写
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++;
                        }
                }
        }
}