สะกดคำทีละตัว
คุณได้เข้าร่วมการแข่งขันสะกดคำ! เพื่อช่วยในการฝึก ลองเขียนโปรแกรมที่แยกคำออกเป็นตัวอักษรทีละตัว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
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));
}
}
}