My desired output to this compiling code is "p----", but as you can see I am frustratingly still getting "panda".
I think I'm not interpreting the String replace API correctly, but as I'm now getting frustrated - I will ask for a hand! Thank you!
James Sands wrote:I think I'm not interpreting the String replace API correctly, but as I'm now getting frustrated - I will ask for a hand! Thank you!
Yes, where the API documentation says
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
I think you missed the first four words.
Another suggestion, while you're taking them: Try to give better variable names. When someone reads your code, do the names "x", "y", "pgr" help them make any sense of what's happening? It's like reading a sentence that goes something like this: "One dy, our grdnr, Bthlmw, dcded he wntd to mrry our tchr, Miss Lsbth." --- this is kind of hard to understand, right? Your code should tell the reader a story of what's happening. Well-written code is about telling people what's going on. The computer could care less because it knows what to do regardless of what name you give.
Your code reads a lot better and I can actually make out the "story" you are trying to tell here. Now, like any good composition, it needs to be broken down into smaller chunks, like paragraphs and chapters and parts. See how you have everything in main()? This is where most people start but soon you'll learn that main() should only be like the preface of a story. The "meat" of the code should be in full-fledged objects, and different sections of the code should be assigned to different objects, each with their own responsibility. Not saying you have to do it now. You'll eventually realize this as you learn more about different object-oriented programming concepts. Good job and good luck!
Thanks again, James.