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 - Explanation: In the above code, we have declared two variables a (base) and b (exponent) and then the program calculates the result of raising the base (a) to the power of the exponent (b) using the Math.pow() method and prints the result.
🌐
W3Schools
w3schools.com › java › ref_math_pow.asp
Java Math pow() Method
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
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); ...
🌐
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.
🌐
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:
🌐
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
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
October 20, 2025 - Returns the value of the first argument raised to the power of the second argument.
🌐
IronPDF
ironpdf.com › ironpdf for java › ironpdf for java blog › java pdf tools › math.pow java
Math.Pow Java (How It Works For Developers)
July 28, 2025 - This article will help you explore the complexities of the Math.pow() method, elucidating its syntax, practical usage, and providing illustrative examples to underscore its functionality.
🌐
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.
🌐
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)); // 10000 System.out.println("2^4 = " + (long) Math.pow(2, 4)); // 16 System.out.println("2^1 = " + (long) Math.pow(2, 1)); // 2 System.out.println("2^0 = " + (long) Math.pow(2, 0)); // 1 // If the second argument is NaN, then the result is NaN.
🌐
Initial Commit
initialcommit.com › blog › pow-function-java-python
Pow() Function in Java and Python
October 19, 2021 - In Java, the Math.pow() function takes exactly two arguments, a base and an exponent. This function is overloaded to provide support for a variety of numerical object types, including floats, doubles, and integers.
🌐
LabEx
labex.io › tutorials › java-java-math-pow-method-117939
Mastering Java's Math Pow Method | LabEx
Create a new file named PowDemo.java in the ~/project directory and open it in a text editor. Add the code below to the file and save it. import java.lang.Math; public class PowDemo { public static void main(String[] args) { } }
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › pow
Java Math pow() - Calculate Power | Vultr Docs
December 3, 2024 - This code snippet computes (2^3), resulting in 8.0. Here, Math.pow() takes two double arguments and returns the base raised to the power of the exponent as a double. Use integer values that Java implicitly converts to double.
🌐
Octoperf
blog.octoperf.com › java-mathpow-through-code-examples
Java Math.pow Through Code Examples - OctoPerf
March 16, 2018 - The java.lang.Math class method pow has several corner cases detailed in the following code: package com.octoperf; import org.junit.Test; import static java.lang.Double.NEGATIVE_INFINITY; import static java.lang.Double.NaN; import static java.lang.Double.POSITIVE_INFINITY; import static org.junit.Assert.assertEquals; public class MathPowTest { private static final double DELTA = 0.001d; @Test public void javaMathPow() { // If the second argument is positive or negative zero, then the result is 1.0.
🌐
Letstacle
letstacle.com › home › java › math pow java | the math pow() method in java
Math pow Java | The Math pow() method in Java - Letstacle
September 13, 2021 - Lastly, we have compared the results with that of Math.pow(). If same, we print “Correct”, “Wrong” if not. ... Like this article? Follow us on Facebook and LinkedIn. You can also subscribe to our weekly Feed. how to import java java example java math pow int math pow java source code
🌐
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)
October 27, 2018 - If you use non‑negative integer powers, there is a recursive solution which doesn't require Math#pow. You can probably extend that technique to negative powers, too. But not fractional powers. ... New to java want to prompt the user for a number for base and one for exponent and print the result This java is not HTML or javascript need Help import java.util.Scanner; public class ExponentCalc { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); // Prompting the user for input of a number int a = base; int b = exponent; System.ou
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › pow
Math.pow() - JavaScript | MDN
Math.pow(NaN, 0) (and the equivalent NaN ** 0) is the only case where NaN doesn't propagate through mathematical operations — it returns 1 despite the operand being NaN. In addition, the behavior where base is 1 and exponent is non-finite (±Infinity or NaN) is different from IEEE 754, which ...