8

Java Program to Calculate the Power of a Number

 2 years ago
source link: https://www.geeksforgeeks.org/videos/java-program-to-calculate-the-power-of-a-number/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Java Program to Calculate the Power of a Number

Java Program to Calculate the Power of a Number
  • 30 Views
  • 03/06/2022

In this video, we will see a Java Program to Calculate the Power of a Number.

To calculate the power of a number we use four different methods: 1. Using loop 2. Using recursive function 3. Using binary exponentiation 4. Using In-built pow() function

In-built function [pow()] of JAVA: Given two numbers base and exponent, pow() function finds x raised to the power of y is function to get the power of a number, but we have to use import java.lang.math in JAVA to use that pow() function. then two numbers are passed.

Syntax: pow(base,exponent);

Pow() parameters: 1) Base: the base value 2) Exponent: exponent of the base

Example:

pow(4 , 2); Then we will get the result as 4^2, which is 16. Input : x = 2, n = 5 Output : 32

Input : x = 6, n = 2 Output : 36

Java Program to Calculate Power of a Number: https://www.geeksforgeeks.org/java-program-to-calculate-power-of-a-number/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK