01/03/2023

Java Program to Find Square and Cube of a Number (N^1, N^2, N^3)

Problem:- Java Program to Calculate the Power of a Number or Given a cube of size n*n*n or Java program to find the Square, Cube and Square Root of an integer or How to square a number in Java or Java Program to print the square of numbers or Simple java Programmes: find Square and cube of a Number or java program to find square and cube of a number or Square and Cube Number Program in Java.

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.

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");
	}
}

Program to Find the Square and Cube of a Number Using the Power Function


The Output of Java Program to Find Square and Cube of a Number (N^1, N^2, N^3)


Java Program to Find Square and Cube of a Number (N^1, N^2, N^3)

Program to Find the Square and Cube of a Number Using the Power Function

Similar to Square and Cube 


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

1 comment:

  1. Sir thanks.🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟🌟

    ReplyDelete