This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
System.out.printf("The temperature is %.2fC or %.2fF.%n", celsius, fahrenheit);
That will print "The temperature is 20.00C or 68.00F.", assuming you haven't got a rounding error producing 67.99F or similar!
Joined: Nov 26, 2008
OH... so I don't need to specify strings at all. The % acts kind of like an escape character?
I had read the tutorial but did not see how to specify a string in addition to numbers. Your post was very helpful
Thanks Campbell!! - jeff
Joined: Oct 13, 2005
You're welcome. You can print a String variable with the %s tags. For entertainment purposes: try the %s tag with a variety of different Objects and see what happens. Then try the %b tag with a variety of different Objects and numbers and see what happens. Be sure to try some "null" references amongst the Objects.