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
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... 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));
🌐
CodeGym
codegym.cc › java blog › java math › math pow() method in java
Math.pow() Method in Java
December 5, 2024 - This is because if you raise any number to the power of 1, the result is the same as the base. If the base is negative/positive zero and the exponent parameter is a negative number, then the result is Infinity.
🌐
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 - Math.pow() is the standard way to perform exponentiation in Java, providing accurate results for both integer and floating-point operations.
🌐
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 - Java, a widely-used and versatile programming language, equips developers with a robust set of mathematical functions to simplify complex operations. One such indispensable function is Math.pow(), which enables the exponentiation of numbers with ease.
🌐
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 - For instance, here’s a java code to take two numbers a and b, and print a raised to power b. public class MathPow { public static void main(String[] args) { int a = 2; int b = 2; double ans = Math.pow(a,b); System.out.println(a+" raised to power "+b+" is "+ans); } }
🌐
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 ...