Use Math.pow(double, double), or statically import pow as such:
import static java.lang.Math.pow;
Answer from Stefan Kendall on Stack OverflowGeeksforGeeks
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));
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
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
Naukri
naukri.com › code360 › library › math-pow-function-in-java
Math pow() Function in Java - Naukri Code 360
July 25, 2025 - Almost there... just a few more seconds
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.
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.
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.
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 ...