Use Math.pow(double, double), or statically import pow as such:
import static java.lang.Math.pow;
Answer from Stefan Kendall on Stack OverflowW3Schools
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....
Videos
Java Math.pow
08:11
Java’s Math.pow() Method Explained - YouTube
Math Methods in Java (Math.pow, Math.sqrt, etc) - YouTube
02:17
Java Tutorial Using Math Power - YouTube
04:50
Power of a Number in Java || Explained using loop and Math.pow() ...
06:01
Java-Math.pow - YouTube
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.
Top answer 1 of 5
12
Use Math.pow(double, double), or statically import pow as such:
import static java.lang.Math.pow;
2 of 5
5
Sure, you just need to call Math.pow(...), as it's a static method in the Math class:
for (int i = 0; i < n; i++) {
functionG[i] = Math.pow(1.25, i);
}
Note that I've changed it to use i rather than n as the second argument.
You could also get your original code to compile using:
import static java.lang.Math.pow;
in the import statements at the top of your code. See the Java Language Specification, section 7.5.3 for details of how this works.
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
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.
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
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.