拼字比賽
你參加了一場拼字比賽!為了幫助自己,你想寫一個程式,把單字分解成一個個字母。
本練習屬於課程
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));
}
}
}