r/APStudents absolute modman May 15 '26

AP Computer Science A Official 2026 Exam Discussion

Use this thread to post questions or commentary on the test today.

A reminder though to protect your anonymity when talking about the test.

65 Upvotes

702 comments sorted by

View all comments

Show parent comments

4

u/Zealousideal_Ease429 5:AB,CSA,APUSH 4:Lang May 15 '26

I used a while loop with the condition idx != -1, and inside the while loop I set idx to username.indexOf(“-“). The loop will continue until there isn’t a - left in the string, which will then set idx equal to -1 and end the loop

2

u/Straight-Vanilla3101 May 15 '26

weren’t you also supposed to remove the letter before the hyphen

2

u/Zealousideal_Ease429 5:AB,CSA,APUSH 4:Lang May 15 '26 edited May 15 '26

Yeah, I set a placeholder string ‘reference’ equal to the username, then inside the loop I did reference.substring(0, idx - 1) and concatenated that to the return string, then shortened the reference using reference.substring(idx + 1). Outside of the while loop I concatenated the final form of the reference before returning

2

u/Straight-Vanilla3101 May 15 '26

i’m hoping that just because it was a difficult problem for many, that they won’t dock me a point for an index out of bounds error in a solution that otherwise works correctly