我“显然”只是在学习编程,我似乎无法弄清楚该怎么做才能摆脱这个错误。错误出现在倒数第二行 - 之前的行:[System.out.print(+windChill);]
这里(写在下面)是 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 + 温度 - Math.pow(windSpeed * 16) + Math.pow(温度 * 16)))
Math.pow
需要两个参数。你只提供一个。
您是说 Math.pow(windSpeed,16)
吗?
Math.pow 声明为
public static double pow(double a,double b)
它返回第一个参数的值的第二个参数的幂。
此外,您在左侧还有一个额外的括号。
关于java - Java 中的 Math.pow 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3800997/