2010-09-27 108 views
3

錯誤我「明明」剛開始學習編程,我似乎無法弄清楚如何才能做,如果這錯誤擺脫。錯誤發生在第二行到最後一行之前:[System.out.print(+ windChill);]Math.pow在Java中

這裏(寫在下面)是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...** 

任何提示或澄清將是非常讚賞。請參閱下面的代碼。先謝謝你。

巴蒂爾

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

    } 

} 

回答

0

Math.pow有兩個參數,它採用第一個參數x和第二參數y表達x^y,但你只有通過單一的參數。你的指數在哪裏?

7

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

Math.pow需要兩個參數。你只提供一個。

你的意思是Math.pow(windSpeed,16)

Math.pow聲明爲 public static double pow(double a,double b) 它返回引發第一個參數的值到第二個參數的冪。

此外,您必須在左手邊一個額外的括號。

+0

+1用於解決這兩個問題。 – st0le 2010-09-27 03:58:26

+1

也從我+1。在發現第一個錯誤後,我不應該停止閱讀。 :) – 2010-09-27 04:00:10

+0

謝謝@ st0le和@Bill :) – 2010-09-27 04:07:07

0

您有一個額外的括號這裏:

double windChill = (((
        ^

要麼刪除或在末尾添加一個)

+0

謝謝你的幫助Prasoon是快樂。 – user459104 2010-09-27 04:15:25

0

的Math.pow功能需要兩個參數,所述底座和所述電源。您只傳遞一個值 - 風速和16的產品,我想你大概的意思是:

Math.pow(windSpeed, 16) 
+0

謝謝你的幫助。 – user459104 2010-09-27 04:14:57

1

的錯誤指示,你在該行的啓動

double windChill = (((35.41 + temperature... 
年底缺少 )

您也可以刪除(在表達式的開頭之一=後,因爲它看起來像不是所有那些真正需要。