Calculating Squares and Cubes in a table or Calculate Cube And Square Program in Java or Writing a Java program to read integer (N) and print the first three powers (N^1, N^2, N^3) example if the user enters a 5 from the keyboard then the output should be 5, 25, 125 Means power of number in 1, 2, 3.

We need to multiply numbers or we can use the power function for that take an example to better understand this problem take a Number 5 as input and multiply with the same number again like 5 * 5 for a cube we need to again multiply with the same number like 5 * 5 * 5 or we can use power function.

also, define the data type of x or y where x is a number and y is the power of x.

We need to multiply numbers or we can use the power function for that take an example to better understand this problem take a Number 5 as input and multiply with the same number again like 5 * 5 for a cube we need to again multiply with the same number like 5 * 5 * 5 or we can use power function.

**Power Function Syntax:**for given example x^y.**pow(x, y)**also, define the data type of x or y where x is a number and y is the power of x.

**See Also:**C Program To Read Integer (N) And Print First Three Powers (N^1, N^2, N^3)## Java Program to Find Square and Cube of a Number

```
import java.util.Scanner;
import java.lang.*;
/* Program By Ghanendra Yadav
Visit http://www.programmingwithbasics.com
*/
public class threenum {
public static void main(String args[]) {
int num, a, b, c;
Scanner sc = new Scanner(System.in);
System.out.print("Enter The Number :\n\n");
num = sc.nextInt();
a = num;
b = num * num;
c = num * num * num;
System.out.println("\nOutput Is = " + a + " ," + b + " ," + c + "\n\n");
}
}
```

Sir thanks.ðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸðŸŒŸ

ReplyDelete