拼字比赛
您参加了一场拼写比赛!为此,您想编写一个程序,把单词分解为一个个字母。
本练习是课程的一部分
Java 中级
练习说明
- 使用正确的方法获取
toSpell的length。 - 使用正确的关键字开始一个 for 循环。
- 为
i设置正确的起始值——需要从第一个字符开始。 - 写出正确的方法,获取
toSpell中第i个位置的char字符。
交互式实操练习
通过完成这段示例代码来试试这个练习。
class Speller {
public static void main(String[] args) {
String toSpell = "conscientious";
// Choose the correct method on toSpell to retrieve its length
int wordLength = toSpell.____();
// Use the right keyword and put the starting correct value into i
____ (int i = ____; i < wordLength; i++) {
// Write down the correct method to retrieve the character at the ith position
System.out.println(toSpell.____(i));
}
}
}