r/codehs • u/L_russ28 • Sep 13 '22
Basic Java. 3.8.14: Replace Letter
Hello! I’ve been struggling with getting my loop right for this problem and I was wondering if I could get some suggestions. Thank you in advance :)
9
Upvotes
View all comments
Show parent comment
1
u/FantasticMrWow Sep 14 '22
Ok apologies I just had to break this down into the things I noticed as I saw them. So you have the for loop iterating over each character of the string, which is good but you need to grab out and store that character to be able to do comparisons on it. When you do those comparisons, you should be doing so with the .equals method on strings and against the parameter variables as there will be cases where you are not checking for y but any fed in character. You can keep the if conditional, but think more about what you want to do if the character your are currently looking at is the character you want to replace, and what you want to do when it isn't. Hope this all helped