เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

สะกดคำทีละตัว

คุณได้เข้าร่วมการแข่งขันสะกดคำ! เพื่อช่วยในการฝึก ลองเขียนโปรแกรมที่แยกคำออกเป็นตัวอักษรทีละตัว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Java ระดับกลาง

ดูคอร์ส

คำแนะนำการฝึกหัด

  • ใช้เมธอดที่ถูกต้องเพื่อดึง length ของ toSpell
  • ใช้คีย์เวิร์ดที่ถูกต้องเพื่อเริ่มต้น for loop
  • กำหนดค่าเริ่มต้นที่ถูกต้องให้กับ i โดยให้เริ่มจากอักขระตัวแรก
  • เขียนเมธอดที่ถูกต้องเพื่อดึงอักขระ (char) ที่ตำแหน่งที่ i ของ toSpell

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

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));
    }
  }
}
แก้ไขและรันโค้ด