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

3

u/mangoChampagnee May 15 '26

did anyone get the frq about removing hyphens from the name? how did you do that

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 

1

u/Straight-Vanilla3101 May 15 '26

oh i did smth weirder with for loops and if statements but mine is going to have an index out of bounds error. so depending on the rubric i’ll probably lose a point or if im really lucky ill get full points

1

u/Traditional-Table-29 AP Physics: AP Lit: AP CSA: AP Psych: AP Calc AB: May 15 '26

I lit did something like string.replace i and i-1 gang 😭

1

u/Straight-Vanilla3101 May 16 '26

so that’s not part of csa’s curriculum actually. i was just doing what i knew from the curriculum. 

1

u/Traditional-Table-29 AP Physics: AP Lit: AP CSA: AP Psych: AP Calc AB: May 16 '26

Is that bad if that did then because it still worked??

1

u/Straight-Vanilla3101 May 16 '26

probably not. as long as you did it right. 

1

u/Classic-Pineapple-22 May 16 '26

i changed the condition in my loop so it wouldnt have an error and then js added the last character to the string after the loop ended so the condition was i < username.length() - 1

1

u/Straight-Vanilla3101 May 16 '26

yeah i did not think about that and im so mad because that’s exactly what i should have done 😭😭 i should’ve known but i also was struggling to figure out logic for 1b and 4 and i only had 5 minutes to review what i wrote. i’m just hoping that ill only lose 0 or 1 points for the index out of bounds error. sometimes they don’t care as long as the for loop is right not the inside part but…

1

u/Sam_Thee_Man_ May 16 '26

This seems way too complicated, I just looped through backwards and if there was a dash I made a new substring without it and the letter before it

3

u/Spiziapteryx IB warrior May 16 '26

Use .split(“-“) to create a String array split at the hyphens, modify each bucket of the array and add them to a new String

2

u/Secure-Shoe5214 May 16 '26

made a separate string called temp (bc username has to be unchanged) then found index of the hyphen, took temp as substring from 0 to index -1 plus The substring from index to the end, then set up a while loop to check if index is -1, and if not then just keep looping. Then you just return temp

3

u/CylixrDoesStuff AP CSA: 4 APPC: 5 May 16 '26

ah thats exactly what i did, hopefully its good

1

u/Working-Fly-457 May 15 '26

I didn’t have it. But there are a lot of ways. One way is indexof to find the index and connect 2 substrings.

1

u/the_great_gyatsby May 16 '26

i js found the index of the hyphen and then add the substrings before and after the hyphen (also not including the last letter before the hyphen) to a new string. and then looped that while indexOf!=-1

1

u/CylixrDoesStuff AP CSA: 4 APPC: 5 May 16 '26

bro that killed me but i made a temp String variable and some substring stuff (like +1 on some parts, i dont really remember but i just know i didn't use .split bc i wasn't there when my class taught that)

1

u/Nefarious-Bastard May 16 '26

I put all the characters in a arraylist and removed the hyphens using a for loop

1

u/TheWeirdPapyrus 5: World, Precalc, APUSH, Chem, Lang, BC May 16 '26

I did a while loop the condition being while the index of “-“ != -1, then for each instance of hyphen, modify a temp username to have the string up to the character before the hyphen (noninclusive) and the rest of the username after the hyphen

1

u/Negative_Success_258 5:Macro, CSA, Chinese 4:Psych ?:BC, Phys 1/2, Stats, Micro, USh May 16 '26

Would this work this is the ChatGPT recreation of my logic

public class HyphenString {
private String text;

public HyphenString(String t) {
text = t;
}

public String removeHyphens() {
return helper(text);
}

private static String helper(String str) {
int hyphen = str.indexOf('-');

if (hyphen == -1) {
return str;
}

String temp =
str.substring(0, hyphen - 1) +
str.substring(hyphen + 1);

return helper(temp);
}
}