Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

How to use printf(Java 5.0) to print variable in specified range?

Thread view: 
Shawn - 14 Dec 2006 14:27 GMT
Hi,

I want to print out two variable values in one line in specified location.
Say, num = 3.14, str = "hello"

I want to print out num at the location between 10 and 15(right
justified) and str at the location between 20 and 30(left justified).

I dont' want to hard-code the spaces, because the spaces in between
depends on the value of num and str and their value can be different
each time.

I don't know Java 5.0 printf can do such a job. I have read its
tutorial, but I cannot find out how to set the location without hard-coding.

Thank you very much.
Christopher Benson-Manica - 14 Dec 2006 20:10 GMT
> I want to print out two variable values in one line in specified location.
> Say, num = 3.14, str = "hello"

format( "%15.5f%-10s", num, str );

> I don't know Java 5.0 printf can do such a job. I have read its
> tutorial, but I cannot find out how to set the location without hard-coding.

Admittedly I'm not 100% sure the above is correct; the documentation
is a good bit more involved than C's printf().

Signature

C. Benson Manica           | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com      | don't, I need to know.  Flames welcome.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.