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

Alexander Nowak
Alexander Nowak
498 Points

Do while loops quiz, second question

Could somebody please check my code and point out what I'm doing wrong.

Thanks guys!

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean isNotRight;


do {
response = console.readLine("Do you understand do while loops");
  isNotRight = (response.equals("No"));
  if (isNotRight)  {
  console.printf("Do you understand do while loops");

  }
  while (isNotRight);
Alexander Nowak
Alexander Nowak
498 Points

Hi guys, got passed this bit and on the last part "Finally, using console.printf print out a formatted string that says "Because you said <response>, you passed the test!"

This is my code and its not working

String response;
boolean isNotRight;


do {
response = console.readLine("Do you understand do while loops");
  isNotRight = (response.equals("No"));
  if (isNotRight)  {
  console.printf("Do you understand do while loops");

  }
  } while (isNotRight);

console.printf("Because you said yes, you passed the test!");

1 Answer

rydavim
rydavim
18,814 Points

Welcome to Treehouse! It looks like you advanced past your original question on your own - nice job!

The printf method is used to print a formatted string using placeholders for variables. Here is an example to get you started:

String name = "Jane Doe";
console.printf("Hello, %s!", name); // This will print: "Hello, Jane Doe!"
Alexander Nowak
Alexander Nowak
498 Points

Perfect! Thank you so much!