Java Data Type How to - Create a table of squares and cubes


We would like to know how to create a table of squares and cubes.


import java.util.Formatter;
//from   w ww.  j a v
public class Main  {
  public static void main(String args[]) {
    Formatter fmt;

    for (int i = 1; i <= 10; i++) {
      fmt = new Formatter();

      fmt.format("%4d %4d %4d", i, i * i, i * i * i);


The code above generates the following result.