Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math.pow errors in Java

Tags:

java

I am 'obviously' just learning programming and I can't seem to figure out what to do in order to get rid if this error. The error is on the second to the last line - the line before: [System.out.print(+windChill);]

Here (written just below), are the list of Java-generated 'possible hints' for the errors that I am getting:

**')' expected
method pow in class java.lang.Math cannot be applied to given types
  required: double,double
  found: double
method pow in class java.lang.Math cannot be applied to given types
  required: double,double
  found: double
operator + cannot be applied to double,pow
incompatible types
  required: doub...**

Any hints or clarification would be most appreciated. Please see code below. Thank you in advance.

Shane

import java.util.Scanner;
public class Main {

   public static void main(String[] args) {
        // TODO code application logic here
        Scanner input = new Scanner(System.in);
        System.out.print("Enter a temperature between -58 and 41 degrees Fahrenheit and press ENTER");
        double temperature = input.nextDouble();
        System.out.print("Enter a wind speed that is 2 miles per hour or faster and press ENTER");      
        double windSpeed = input.nextDouble();
        double windChill = (((35.41 + temperature - Math.pow(windSpeed * 16) + Math.pow(temperature * 16)));
        System.out.print(+windChill);

    }

}
like image 946
user459104 Avatar asked Feb 26 '23 04:02

user459104


2 Answers

(((35.41 + temperature - Math.pow(windSpeed * 16) + Math.pow(temperature * 16)))

Math.pow requires two arguments. You are providing just one.

Did you mean Math.pow(windSpeed,16)?

Math.pow is declared as public static double pow(double a,double b) It returns the value of the first argument raised to the power of the second argument.

In addition you have an extra parenthesis at the left hand side.

like image 132
Prasoon Saurav Avatar answered Mar 07 '23 07:03

Prasoon Saurav


The error indicates that you're missing a ) at the end of the line that starts

double windChill = (((35.41 + temperature...

You could also remove one of the ( at the beginning of the expression after the =, since it looks like not all of those are really needed.

like image 39
Bill the Lizard Avatar answered Mar 07 '23 06:03

Bill the Lizard