Creates a table of squares and cubes using minimum field width using Formatter Class.

This example demonstrates the use of formatter class and also using minimum field width.

Output::

1      1       1

2      4      8

3       9   27

.         .       .

.         .       .

import java.util.*;

class FormatterExample{

public static void main(String a[]){

Formatter fm= new Formatter();

for(int j=1; j<=5; j++){

fm.format("%5d %5d %5d", i, i*i, i*i*i);

System.out.println(fm);

}

}
}
Advertisements

2 thoughts on “Creates a table of squares and cubes using minimum field width using Formatter Class.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s