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 trialluis cantu
927 PointsIf I use System.Out.Println in the try and catch block the execution fails, Why has to use Println and then Printf ?
I could complete this excercise,but I wanted to know what happens if I use Println on booth sentences I did... and the execution fails. Then I changed the second sentence to printf as the video shows and the execution pass. Whis this happens?
2 Answers
Aamir Mirza
25,077 PointsThis is an old question, but I ran into the same problem.
The f in printf stands for "format", that's why you can pass in strings with %s, %d etc. and format them to include strings, integers and so on.
println on the other hand does not format strings, and only takes in one argument, that's why it throws an exception.
Trent Christofferson
18,846 PointsIt should be typed in all lower case except for 'System'. It should be the same casing as printf. Also an example of how to get the same result using printf and println: System.out.println("My name is " + name); vs System.out.printf("My name is %s", name);