Java Program to Find Square and Cube of a Number (N^1, N^2, N^3)
belongs to collection: Example of Simple Programs In JAVA Programming
All Answers
need an explanation for this answer? contact us directly to get an explanation for this answer
Method 1:- Simple Without Using Power Function
import java.util.Scanner;
import java.lang.*;
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");
}
}
Output:
Enter The Number :
5
Output Is = 5 ,25 ,125
need an explanation for this answer? contact us directly to get an explanation for this answertotal answers (2)
Method 2:- Using Power Function
Output:
Enter The Number :
10
Output Is = 10.0 ,100.0 ,1000.0
need an explanation for this answer? contact us directly to get an explanation for this answer