Dremendo Tag Line

Print square and cube of a number in Java

Java Output - Question 12

In this question, we will see how to print the square and cube of a number in java programming using the java output. To know more about java output click on the java output lesson.

Q12) Write a program in java to print the square and cube of int a=8.

Program

public class Q12
{
    public static void main(String args[])
    {
        int a=8;
        System.out.println("Square of "+ a + "=" + (a*a));
        System.out.println("Cube of " + a + "=" + (a*a*a));
    }
}

Output

Square of 8=64
Cube of 8=512
video-poster