Print Table Of Squares And Cubes in Java

Question: Using only the programming techniques you learned in this chapter, write an application that calculates the squares and cubes of the numbers from 0 to 10 and prints the resulting values in table format, as shown below. [Note: This program does not require any input from the user.]

number square cube
0 0 0
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000

Java Program To Print Table Of Squares And Cubes

/*
 *       Filename:  SquaresCubes.java
 *
 *    Description:  Exercise 2.31 - Table of Squares and Cubes
 *
 *@Author:  Bilal Tahir Khan Meo
 *  Website: https://www.codeblah.com
 *
 * =====================================================================================
 */
public class SquaresCubes{
    public static void main(String[] args){
        System.out.println("number square cube");
        System.out.printf("%d      %d      %d\n", 0, 0*2, 0*3);
        System.out.printf("%d      %d      %d\n", 1, 1*1, 1*1*1);
        System.out.printf("%d      %d      %d\n", 2, 2*2, 2*2*2);
        System.out.printf("%d      %d      %d\n", 3, 3*3, 3*3*3);
        System.out.printf("%d      %d     %d\n", 4, 4*4, 4*4*4);
        System.out.printf("%d      %d     %d\n", 5, 5*5, 5*5*5);
        System.out.printf("%d      %d     %d\n", 6, 6*6, 6*6*6);
        System.out.printf("%d      %d     %d\n", 7, 7*7, 7*7*7);
        System.out.printf("%d      %d     %d\n", 8, 8*8, 8*8*8);
        System.out.printf("%d      %d     %d\n", 9, 9*9, 9*9*9);
        System.out.printf("%d     %d    %d\n", 10, 10*10, 10*10*10);
    }
}