Calculates the Squares and Cubes in Java

In this Java program, the application will display in a table the value of the squares and cubes from 1 to 10.

This is the same solution of Deitel & Deitel exercises 2.33 in Chapter 2. 
  • Write an application that calculates the squares and cubes of the numbers from 1 to 10 and prints the resulting values in table.

public class SquareCube{

public static void main (String args[]){

//Declare the variables
int square, cube, number= 1;

//Dispay the header f the table
System.out.printf("Number\tSquare\tCube\n");

//Loop value ntil reached no.10;
while (number <= 10){
square = number * number;
cube = square * number;
number ++;

System.out.printf(" %d\t \t%d\t \t%d\n", number, square, cube);

}

System.exit(0);
}
}

Here is the output.

Comments

Popular posts from this blog

Calculate the Sum, Product, Difference & Quotient in Java

Determine Two Numbers which is the largest or Both Numbers are Equal in Java