我正在練習在我的主函數中測試我的方法(它是計算元音的數量)。 我想知道如何在這裏實現我的代碼?我的代碼中是否也存在缺陷?如何在我的主要方法中測試另一種方法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)。 –