PROGRAM FOR SQURE AND CUBE OF A NUMBER

The logic in this program, first we have to do multiplication of two number( and assiging multiplication vlaue to num1 variable in that time we will get squre of a number.

In the next step we have to do multiplication of num value and num1 value and assiging the multiplication value to num2 variable then only we will get cube of a number.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.Scanner;
public class SqareCubenum
{
    public static void main(String[] args)
    {
        int num,num1,num2;
        Scanner x = new Scanner(System.in);
        num= x.nextInt();
        num1=num*num;
        num2=num*num1;
        System.out.println("enter number is:"+num);
        System.out.println("square  number is:"+num1);
        System.out.println("cube number is:"+num2);
    }
}

Output :Square and Cube of a Number

gcdn