Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java Notes

Formatted Output

Java 5 implements formatted output with printf(). This concept will be very familiar to C and Fortran programmers. A good introduction to it can be found in the following article by John Zukowski.

Taming Tiger: Formatted output

Some simple examples

format(). Amazingly, there was no built-in way to right justify numbers in Java until Java 5. You had to use if or while to build the padding yoursefl. Java 5 now provides the format() method (and in some cases also the equivalent printf() method from C)..

The format() method's first parameter is a string that specifies how to convert a number. For integers you would typically use a "%" followed by the number of columns you want the integer to be right justified in, followed by a decimal conversion specifier "d". The second parameter would be the number you want to convert. For example,

int n = 2;
System.out.format("%3d", n);

This would print the number in three columns, that is with two blanks followed by 2.

You can put other non-% characters in front or back of the conversion specification, and they will simply appear literally. For example,

int n = 2;
System.out.format("| %3d |", n);

would print

|   2 |

Complete format specification

Read the Java API documentation on the Formatter class for a specification of the format codes.

Ask programming questions?

 

 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (post your own) View All Comments Latest 10 Comments:

i am a student and i want to know about the paramid that how to make the paramid...
that's it...
take care

Posted by suhaib khan on Tuesday, 03.30.10 @ 18:02pm | #95977

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.

[an error occurred while processing this directive]