開始使用免費開始

拼字比賽

你參加了一場拼字比賽!為了幫助自己,你想寫一個程式,把單字分解成一個個字母。

本練習屬於課程

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));
    }
  }
}
編輯並執行程式碼