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.
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.
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
Post a Comment