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 Data Structures - Retired Getting There Object Inheritance

Arcee Palabrica
Arcee Palabrica
8,100 Points

Confused with the proper placement of escape quotes.

Sorry... Got a little confused in the quote placement there. in this code:

String name = "Bob";
System.out.print("My name is " + name);

where do we properly place them to get these following results?

  1. "My name is Bob."
  2. My name is "Bob."

2 Answers

andren
andren
28,558 Points

To insert a quote into a String you just need to type \" anywhere you want the quote to be placed. So to produce your examples the code would look like this:

String name = "Bob";
// Example 1
System.out.println("\"My name is " + name + ".\"");

// Example 2
System.out.println("My name is \"" + name + ".\"");
Arcee Palabrica
Arcee Palabrica
8,100 Points

Thanks.. I get it now... have a great day... :)