Library › Coding AI › High school students
See why your substring answer is off by one
Practice: Asking for a format you can use. About 5 minutes.
About this exercise
Your answer to a Java practice question was "MPUT" but the key says otherwise. Ask for exactly 3 numbered lines: line 1 lists every letter of COMPUTER with its index like 'C0 O1 M2 ...'; line 2 starts 'Takes:' and says which indexes substring(2, 5) uses; line 3 starts 'Result:' with the right answer in quotes and what you included by mistake. No code blocks, under 60 words.
Common mistakes when you ask AI for this
- Getting a lecture. The AI explains String methods in general instead of your exact mistake. Try: Say: "Exactly 3 numbered lines."
- No index map. Without seeing each letter's index, it's hard to see where you went off. Try: Ask: "Line 1: every letter with its index, like C0 O1 M2."
- No labels. Unlabeled lines blur the rule and the answer together. Try: Add: "Line 2 starts 'Takes:', line 3 starts 'Result:'."
- Code you didn't need. The AI may write a whole Java program to demonstrate. Try: Add: "No code."
What a strong prompt includes
- Sets the number of lines
- Asks for an index map
- Gives the labels
- Asks what you got wrong
- Rules out code
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)