Write a program that inputs a number from user and displays it square and cube.

public static void main(String[] args) {

Scanner x=new Scanner(System.in);

int n,a,b;

System.out.println(“Enter number”);

n=x.nextInt();

a=n*n;

b=n*n*n;

System.out.println(“Square is=”+a);

System.out.println(“cube is=”+b);

}

Output:

run:

Enter  number

6

Square is=36

cube is=216

BUILD SUCCESSFUL (total time: 3 seconds)

Leave a Reply

Your email address will not be published. Required fields are marked *