Wednesday, March 27, 2013

Java;Notes - 14.) Formatting Output

In Java the best way to format an outcome in terms of numbers is to use the "printf" function So it would look something like this:

  1. System.out.printf("Hello %s, next year you will be %d", name, age);
This is the conversion chart for printf:

Here is the Flag chart for printf: 
Note: You can use multiple flags with printf so long as all negatives are enclosed in parenthesis.

Telling date and time:
Since we are experimenting with printf we can also use it to print out the date and time like so:
  1. System.out.printf("%tc", newDate());
Here is a helpful chart for Date Conversions under printf:



One last graph for printf format specifiers syntax layout:



No comments:

Post a Comment