有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在使用时缺少返回语句。查拉特

我需要写一个返回单词中元音数的代码,我的代码中不断出现错误,要求返回一个缺失的语句。有什么解决办法吗?:三,

import java.util.*;

public class vowels
{
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    System.out.println("Please type your name.");
    String name = input.nextLine();
    System.out.println("Congratulations, your name has "+
                        countVowels(name) +" vowels.");
}
public static int countVowels(String str)
{
    int count = 0;
    for (int i=0; i < str.length(); i++)
    {
        // char c = str.charAt(i);
        if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'o' || str.charAt(i) == 'i' || str.charAt(i) == 'u')
        count = count + 1;
    }
}
}

共 (0) 个答案