开始使用免费开始使用

拼字比赛

您参加了一场拼写比赛!为此,您想编写一个程序,把单词分解为一个个字母。

本练习是课程的一部分

Java 中级

查看课程

练习说明

  • 使用正确的方法获取 toSpelllength
  • 使用正确的关键字开始一个 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));
    }
  }
}
编辑并运行代码