简体   繁体   English

Java中的Math.pow错误

[英]Math.pow errors in 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);] 错误发生在第二行到最后一行 - 前一行:[System.out.print(+ windChill);]

Here (written just below), are the list of Java-generated 'possible hints' for the errors that I am getting: 这里(下面写的)是Java生成的“可能的提示”列表,用于我得到的错误:

**')' 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);

    }

}

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

Math.pow requires two arguments. Math.pow需要两个参数。 You are providing just one. 你只提供一个。

Did you mean Math.pow(windSpeed,16) ? 你的意思是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. Math.pow声明为public static double pow(double a,double b)它将第一个参数的值返回到第二个参数的幂。

In addition you have an extra parenthesis at the left hand side. 此外,左侧还有一个额外的括号。

The error indicates that you're missing a ) at the end of the line that starts 该错误表示您在启动的行的末尾缺少a )

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. 您也可以删除其中一个(=之后的表达式的开头,因为看起来并非所有这些都是真正需要的。

Math.pow takes two arguments, in an expression x^y it takes first parameter x and second parameter y , but you're only passing single arguments. Math.pow接受两个参数,在表达式x^y它接受第一个参数x和第二个参数y ,但是你只传递单个参数。 Where's your exponent? 你的指数在哪里?

You have an extra parenthesis here: 这里有一个额外的括号:

 double windChill = (((
                    ^

either remove that or add a ) at the end. 要么删除它,要么添加a )

The Math.pow function needs two arguments, the base and the power. Math.pow函数需要两个参数,即基数和幂。 You are only passing in one value - the product of windSpeed and 16. I think you probably mean: 你只传递一个值 - windSpeed和16的产物。我想你可能意味着:

Math.pow(windSpeed, 16)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM