我正在练习在我的主函数中测试我的方法(它是计算元音的数量)。 我想知道如何在这里实现我的代码?我的代码中是否也存在缺陷?如何在我的主要方法中测试另一种方法java
public class MethodPractice{
public static void main(String[] args){
numVowels(howcanitesthere); //i know this is wrong, just trying smth..
}
public static int numVowels(String s){
String text = ("");
int count = 0;
for(int i = 0; i < text.length() ;i ++){
char c = text.charAt(i);
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
count++;
}
}
System.out.println(count);
}
}
你可以..它传递一个字符串?我不明白你在挣扎着什么。 – Eric
我不知道你真的要求我们帮忙。你想要什么输入和这个测试的结果是? – millimoose
欢迎来到StackOverflow!你可以设置你的问题的格式,以便代码更易读;请参考[Markdown帮助页面](http://stackoverflow.com/editing-help)或[编辑问题时提供的格式参考](http://codinghorror.typepad.com/.a/6a0120a85dcdae970b0120a86e29f4970b- PI)。 –