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

import static java.lang.Math.pow;
Answer from Stefan Kendall on Stack Overflow
🌐
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. (Negative zeros can occur due to the rounding of numbers between zero and the smallest representable negative non-zero number). If the exponent parameter is NaN, the output will also be NaN. 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); System.out.println(answer); } } This will output NaN.
🌐
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) { } }
🌐
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));
🌐
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.
Find elsewhere
🌐
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.
🌐
Codecademy
codecademy.com › docs › java › math methods › .pow()
Java | Math Methods | .pow() | Codecademy
June 23, 2025 - This method is part of the java.lang.Math class and provides a convenient way to compute mathematical powers without manually implementing multiplication loops.
🌐
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
🌐
Reddit
reddit.com › r/learnprogramming › [java] the import java.util.math cannot be resolved
r/learnprogramming on Reddit: [Java] The import java.util.Math cannot be resolved
February 13, 2014 -

I'm writing a program to calculate the wind chill based on a temperature and wind speed entered by the user. The formula to calculate wind chill is

Wind Chill = 35.74 + 0.6215T - 35.75V0.16 + 0.4275TV0.16

My current code is

import java.util.Scanner;
import java.util.Math;
public class WindChill {

public static void main(String[] args) {
	
	//Declare variables

	double windChill;
	double temperature;
	int    windSpeed;

//Ask the user for temperature and wind speed

System.out.print("Enter the temperature (Fahrenheit):  ");
	Scanner input = new Scanner (System.in);
	temperature = input.nextDouble();

System.out.print("Enter the wind speed(mph):  ");
	windSpeed = input.nextInt();

	
//Display the wind chill value

windChill = (35.74+(0.6215*temperature)) - (Math.pow(35.75*windSpeed,0.16)) + (Math.pow(0.4275*temperature*windSpeed,0.16));	
System.out.print("The wind chill index is " + windChill);
}

}

I get an error in the IDE on line 2 that says "the import java.util.Math could not be resolved". Also, when I try to run the program, I get the error message

"Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at WindChill.main(WindChill.java:6)

I checked my installed JREs and I am using JRE7. Can anybody tell me what is wrong?

🌐
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.
🌐
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
🌐
Know Program
knowprogram.com › home › math.pow() method in java
Math.pow() Method in Java - Know Program
September 7, 2022 - import static java.lang.Math.*; public class Test{ public static void main(String[] args) { System.out.println(pow(2, 3)); // 8 } }
🌐
Initial Commit
initialcommit.com › blog › pow-function-java-python
Pow() Function in Java and Python
As with the Java example, this script will print out the value of 34, 81. We can confirm again that multiplying 3 by itself 4 times results in the same value: import math base = 3 exponent = 4 raised_value = 1 for i in range(exponent): raised_value = raised_value * base print(raised_value) The pow() function isn't limited to working with positive values.
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 27610675 › beginners-java-help-needed-using-eclipse
Beginner's Java - Help Needed Using Eclipse - Stack Overflow
Your program would display: Math.pow(2.0, 3.0) = 8.0. When calling a method that accepts doubles, use numbers with at least one decimal digit like the example above, even if it's a zero. Remember that numbers with decimals are double literals. Try to use values that will produce easily verifiable results. ... double pow(double a, double b): Use 3.0 and 2.0 double sqrt(double x): Use 25.0 int max(int a, int b): Use 6 and 2 double max(double a, double b): Use -50.0 and 7.0 static double random()
🌐
Know Program
knowprogram.com › home › import math class in java
Import Math Class in Java - Know Program
June 27, 2023 - Since java.lang package is the default package to every Java program, therefore there is no need to import the Math class explicitly in the program. But all variables and methods of Math class are static. There are two ways to access static variables or methods of Math class, Directly through it’s class name (like Math.pow(), Math.sqrt())
🌐
Reddit
reddit.com › r/javahelp › math.pow not working but math.abs is. trying to solve an equation.
r/javahelp on Reddit: Math.pow not working but Math.abs is. Trying to solve an equation.
November 29, 2014 -

import java.util.Scanner; public class FormulaEvaluator { /* *Evaluate the expression. * *@param args Command line arguments (not used). */

public static void main(String[] args) {

  Scanner userInput = new Scanner(System.in);
  String name = "";
  double x = 0.0;
  double value = 0.0;
  //Prompt the user for a value of x
  System.out.print("Enter a value for x: "); 
  x = userInput.nextDouble();
  //Calculate the value of x using user input
  value = Math.pow(x);
  System.out.print("Result:" + value);

} }

My error message: FormulaEvaluator.java:27: error: method pow in class Math cannot be applied to given types; value = Math.pow(x); ^ required: double,double found: double reason: actual and formal argument lists differ in length 1 error

We're having to solve a long formula as a project but when I try to raise the x variable, which is the user input, to a power it doesn't compile and gives the error. It works fine when using Math.abs so I'm not really sure what's going on. Thanks in advance.