Use Math.pow(double, double), or statically import pow as such:

import static java.lang.Math.pow;
Answer from Stefan Kendall on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › math-pow-method-in-java-with-example
Math pow() Method in Java with Example - GeeksforGeeks
March 28, 2025 - // importing java.lang package ... result; // Here second argument is NaN, // output will be NaN result = Math.pow(2, nan); System.out.println(result); // Here second argument is zero result = Math.pow(1254, 0); ...
🌐
CodeGym
codegym.cc › java blog › java math › math pow() method in java
Math.pow() Method in Java
December 5, 2024 - Let’s consider one instance where this 3rd situation can happen. import java.lang.Math; public class MyClass{ public static void main(String []args){ double base = 5; double exponent = Double.NaN; double answer = Math.pow(base, exponent); ...
🌐
Programiz
programiz.com › java-programming › library › math › pow
Java Math pow()
Try Programiz PRO! ... The pow() method returns the result of the first argument raised to the power of the second argument. class Main { public static void main(String[] args) { // computes 5 raised to the power 3 System.out.println(Math.pow(5, 3)); } } // Output: 125.0
🌐
W3Schools
w3schools.com › java › ref_math_pow.asp
Java Math pow() Method
System.out.println(Math.pow(2, 8)); System.out.println(Math.pow(3, 4)); System.out.println(Math.pow(9, 0.5)); System.out.println(Math.pow(8, -1)); System.out.println(Math.pow(10, -2));
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java math.pow() method
Java Math.pow() Method
September 1, 2008 - The Java Math pow(double a, double b) returns the value of the first argument raised to the power of the second argument.
🌐
Codecademy
codecademy.com › docs › java › math methods › .pow()
Java | Math Methods | .pow() | Codecademy
June 23, 2025 - The method returns a double value representing the result of base raised to the power of exponent. Special cases include returning NaN for invalid operations, Infinity for overflow conditions, and specific handling for zero and one values. This example demonstrates the fundamental usage of the Math.pow() method with basic integer exponents:
🌐
Octoperf
blog.octoperf.com › java-mathpow-through-code-examples
Java Math.pow Through Code Examples - OctoPerf
Request a Demo · Let's see the ... void simpleExample() { assertEquals(1024d, Math.pow(2d, 10d), DELTA); } } The 10th power of 2 is 1024....
Find elsewhere
🌐
Initial Commit
initialcommit.com › blog › pow-function-java-python
Pow() Function in Java and Python
For this first example, we'll implement ... java.lang.Math; public class PowerCalculator{ public static void main(String []args){ int base = 3; int exponent = 4; double raised_value = Math.pow(base, exponent); System.out.println(raised_value); ...
🌐
Javatpoint
javatpoint.com › java-math-pow-method
Java Math.pow() Method
Java Math.pow() method with Examples on abs(), min(), max(), avg(), round(), ceil(), floor(), pow(), sqrt(), sin(), cos(), tan(), exp() etc.
🌐
Baeldung
baeldung.com › home › java › java numbers › using math.pow in java
Using Math.pow in Java | Baeldung
January 8, 2024 - DecimalFormat df = new DecimalFormat(".00"); double dblResult = Math.pow(4.2, 3); In this quick article, we have seen how to use the Java’s Math.pow() method to calculate the power of any given base.
🌐
Educative
educative.io › answers › how-to-use-the-mathpow-method-in-java
How to use the Math.pow() method in Java
The pow() method is a part of java.lang.Math class, you need to import this class in your code to use the function.
🌐
Coderanch
coderanch.com › t › 701213 › java › import-java-util-Scanner-result
Using import java.util.Scanner; to get result of Math.pow to get result (Beginning Java forum at Coderanch)
Then you use result = Math.pow(a, b); but the variables a and b have not been initialized. You never get your exponent from the keyboard input. So my advice to you is to start over and add only one or a few lines at a time, then see if the program compiles.
🌐
IronPDF
ironpdf.com › ironpdf for java › ironpdf for java blog › java pdf tools › math.pow java
Math.Pow Java (How It Works For Developers)
March 27, 2024 - When working with negative finite odd integers, it's important to note that raising a negative number to an odd exponent will result in a negative outcome. For instance, Math.pow(-3, 5) would yield -243. Let's explore some examples to understand ...
🌐
Carmatec
carmatec.com › home › java math.pow() explained: the java power function
Java Math.pow() Explained: The Java Power Function
January 7, 2026 - A negative base with a non-integer exponent typically returns NaN (e.g., Math.pow(-4, 0.5) → square root of negative). Bases of magnitude greater than 1 raised to +Infinity return +Infinity.
🌐
CodeAhoy
codeahoy.com › java › Math-Pow-method-JI_11
Java Math.pow() Method with Examples | CodeAhoy
October 26, 2016 - int result = (int)Math.pow(3, 2) // result = 9 · Here’s a complete example that also shows the special case when the second argument is NaN. import static java.lang.Double.NaN; public class Main { public static void main(String[] args) { System.out.println("10^4 = " + (long) Math.pow(10, 4)); // ...
🌐
Studytonight
studytonight.com › java-examples › java-math-pow-method
Java Math pow() Method - Studytonight
The general signature of the method ... { public static void main(String[] args) { double d1 = Math.pow(3, 5); double d2 = Math.pow(3.5, 1.5); int i = (int) Math.pow(3.5, 1.5);//Casting is required for int type System.out.println("3 ...