Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Looping until the value passes

Peter Kurkowski
Peter Kurkowski
595 Points

I dont understand what this question is asking me to do regarding formatted string.

My Code:

String response; boolean noResponse; do { response = console.readLine("Do you understand do while loops?"); noResponse = (response.equalsIgnoreCase("no")); if (noResponse) { console.printf("Try again."); } } while (noResponse); String closing = console.printf("Because you said %s, you passed the test!");

The question is asking for me to enter a formatted string that includes the console.readLine value entered for response. I'm confused how i would create another string that includes the value entered for a previously declared string.

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean noResponse;
do {
  response = console.readLine("Do you understand do while loops?");
  noResponse = (response.equalsIgnoreCase("no"));
  if (noResponse) {
    console.printf("Try again.");
  }
} while (noResponse);
String closing = console.printf("Because you said %s, you passed the test!");

2 Answers

Peter Kurkowski
Peter Kurkowski
595 Points

I solved the problem myself by looking back at old code:

console.printf("Because you said %s, you passed the test!",response);

but i hate doing that, it feels like cheating.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Way to go! Everyone looks at old code so don't worry about it. I like to keep snippets of code and other notes for reference.

Peter Kurkowski
Peter Kurkowski
595 Points

I just feel like its cheating when ive followed the video examples, written out the code he has then i go and just copy it in the exercises. i feel like that doesnt help me fully grasp the concepts. is this something i should not worry about?

Peter Kurkowski
Peter Kurkowski
595 Points

I just feel like its cheating when ive followed the video examples, written out the code he has then i go and just copy it in the exercises. i feel like that doesnt help me fully grasp the concepts. is this something i should not worry about?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

In short, don't worry about it. It's hard to remember all of the methods and their signatures at first. After more experience looking at lots of code it becomes second nature to construct the statements correctly. Manually repeating proper code is the first step. Using the lessons to synthesize new code come next. Then finally coding from a blank slate.

Peter Kurkowski
Peter Kurkowski
595 Points

Thanks for the help! Really appreciated.