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

import static java.lang.Math.pow;
Answer from Stefan Kendall on Stack Overflow
🌐
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));
🌐
W3Schools
w3schools.com › java › java_math.asp
Java Math
The Java Math class has many methods ... to find the highest value of x and y: ... Note: The Math.pow() method always returns a double, even if the result is a whole number....
🌐
W3Schools
w3schools.com › java › java_ref_math.asp
Java Math Reference
The Java Math class has many methods that allows you to perform mathematical tasks on numbers.
🌐
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 - Math.pow() is the standard way to perform exponentiation in Java, providing accurate results for both integer and floating-point operations.
Find elsewhere
🌐
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.
🌐
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
🌐
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.
🌐
Baeldung
baeldung.com › home › java › java numbers › using math.pow in java
Using Math.pow in Java | Baeldung
January 8, 2024 - Learn how to use the Java's Math.pow() method to calculate the power of any given base quickly.
🌐
W3Schools
w3schools.com › java › tryjava.asp
W3Schools online JAVA editor
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
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)
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
🌐
Octoperf
octoperf.com › blog › 2018 › 03 › 16 › java-math-pow
Java Math.pow Through Code Examples - OctoPerf
It's a static method on Math class, which means you don't have to instantiate a Math instance to call it. The power of a number is the number of times the number is multiplied by itself.
🌐
CodeAhoy
codeahoy.com › java › Math-Pow-method-JI_11
Java Math.pow() Method with Examples | CodeAhoy
October 26, 2016 - This is a static method like all other methods of the Math class and can be called directly on the Math class as Math.pow(...). ... This method returns a^b or a raised to the power b as a double value. Here’s a simple example where we raise 3 to the power of 2, or 3^2, and convert the result ...
🌐
Blogger
javahungry.blogspot.com › 2022 › 10 › import-math-class-java.html
How to import Math class in Java with examples | Java Hungry
import java.lang.Math; According to Oracle docs, all the methods and variables are static. We can access the static variables or static methods of Math class by using two ways. 1. Using Class Name 2. Using static import statement · We can easily access the Math class static variables and methods by using class name i.e. Math.pow(), Math.sqrt(), etc.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-class
Java Math Class - GeeksforGeeks
July 23, 2025 - System.out.println("pow(2.0, 2.0) is " + Math.pow(2.0, 2.0)); System.out.println("pow(10.0, 3.5) is " + Math.pow(10.0, 3.5)); System.out.println("pow(8, -1) is " + Math.pow(8, -1)); // sqrt(x) returns the square root of x.
🌐
iO Flood
ioflood.com › blog › math-pow-java
Java's Math.pow() Function | Guide to Exponents in Java
February 29, 2024 - In this example, we use the Math.pow() function to raise 2 to the power of 3, which results in 8.0. The function is part of the Math class in Java, which provides a collection of methods that allows you to perform mathematical operations.