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.
Discussions

eclipse - How can I fix the project build path error? I can't import the java.lang.math for a Java 8/9 Calculator app - Stack Overflow
I am developing a simple calculator application in Java 8/9 in Eclipse. I am working on the power operation (as in "to the power of" used in math). I want to use the Math.power() instead of a for loop. However, I am having trouble importing the java math package into the program. More on stackoverflow.com
🌐 stackoverflow.com
eclipse - How to get the rest of java Math funtions? - Stack Overflow
I am using the Eclipse IDE and the CodeNameOne toolkit for all my programming at the moment and as some of my programs are now requiring some more complicated math I realized that I am missing some of the Math functions. The most important ones being pow(), acos(), and asin(). Any ideas on how to get them added in? All of my googling has been for not so far. I have imported the class using java... More on stackoverflow.com
🌐 stackoverflow.com
[Java] The import java.util.Math cannot be resolved
it is java.lang.Math More on reddit.com
🌐 r/learnprogramming
9
5
February 13, 2014
Math.pow not working but Math.abs is. Trying to solve an equation.
The syntax for Math.pow is Math.pow(base, exponent). What's your exponent? More on reddit.com
🌐 r/javahelp
8
4
November 22, 2014
🌐
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));
🌐
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.
Find elsewhere
🌐
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.
🌐
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 › java › lang › math_pow.htm
Java - Math pow(double a, double b) method
The Java Math pow(double a, double b) returns the value of the first argument raised to the power of the second argument. Special cases − then the result is positive infinity. If then the result is positive zero.
🌐
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?

🌐
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.
🌐
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 } }
🌐
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())
🌐
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
🌐
Octoperf
octoperf.com › blog › 2018 › 03 › 16 › java-math-pow
Java Math.pow Through Code Examples - OctoPerf
March 16, 2018 - 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.
🌐
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 22, 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.