我正在编写一个程序来计算字符串中元音的数量,如果元音多于辅音,则返回 true。如果不是,则为假。这是一项家庭作业,但跑步者不是其中的一部分。我想测试一下我的程序是否有效,它应该(希望!)。
现在,对于我们所有的家庭作业和实验室,通常都会提供跑步者。我们从来没有被教过如何编写一个,这很糟糕,因为我想检查我的代码。我尝试模仿过去的跑步者,但我的跑步者不断出现错误,其中一些显示为:“找不到符号”如何为这个程序创建跑步者?
这是我的代码:
import static java.lang.System.*;
public class StringAnalyzer {
//String word;
public static boolean hasMoreVowelsThanConsonants(String word) {
// String word = string.toUpperCase();
int vowelCount;
int newLength;
for (vowelCount = 0; word.length() >= 1; vowelCount++) {
if (word.indexOf("A") != 1) {
vowelCount++;
} else if (word.indexOf("E") != 1) {
vowelCount++;
} else if (word.indexOf("I") != 1) {
vowelCount++;
} else if (word.indexOf("O") != 1) {
vowelCount++;
} else if (word.indexOf("U") != 1) {
vowelCount++;
}
newLength = (word.length() - vowelCount);
if (vowelCount > newLength) {
return true;
} else {
return false;
}
}
return true;
}
}
如果你发现任何问题,我总是除了建议:)
这是我的“跑步者”(它很糟糕,哈哈):
导入静态 java.lang.System.*;
import static java.lang.System.*;
public class StringAnalyzerRunnerCDRunner {
public static void main(String[] args) {
hasMoreVowelsThanConsonants("DOG");
}
}
谢谢 :)