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 Objects Meet Objects Final

Jacob Klug
Jacob Klug
469 Points

System.out.printf(" It was %s but chris switched it to %s %n", before, dispenser.getCharacterName()); not working

when I write that its suppost to print out It was yoda chris switched it to dark vader. For me it says It was yoda but chris switched it to yoda. What did i do wrong this is my code. System.out.printf(" It was %s but chris switched it to %s %n", before, dispenser.getCharacterName());

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Jacob,

Without seeing all your code, it's really difficult to say why. I don't see the before variable being set, but if you are getting the same name for the placeholders, then something is off with that variable and how it's being set. Review the video and double check all your code (the problem is not with the line you shared). If you are using Treehouse's Workspaces, you can share a snapshot of your Workspace.

Hope you get it figured out. :) :dizzy:

HIDAYATULLAH ARGHANDABI
HIDAYATULLAH ARGHANDABI
21,058 Points

hi when you are work in compiler like eclipse or intelja dont write printf write print or printLine instead. check about these key words from interenet

I had a similar question about the flip from printf to print and println

I have used print and println from System.out .... etc.

printf seems to work like c's call (where I would concatenate variables and literal strings, printf in Java looks more like C.

Could you explain reasoning? Has printf in Java been deprecated?