簡體   English   中英

嘗試在 Java 中計算 5 個數字的平均值時出現“非法的類型開頭”

[英]“illegal start of type” when trying to calculate average in Java for 5 numbers

我在 Udacity Android 開發人員中進行了測試

public class MyCalculator {

    int input1 = 10;
    int input2 = 20;
    int input3 = 30;
    int input4 = 40;
    int input5 = 50;

    public float average() {
        // TODO: write java code to calculate the average for all input variables

         return 0;
    }
}

我必須給出答案才能繼續學習,我已經嘗試了一切,但它沒有接受答案。 預計該方法計算結果為 30.0 作為float

錯誤

|       public float average(( input1 + input2 + input3 + input4 + input5)/5 ) {
illegal start of type

|       System.out.print(average);
<identifier> expected

|       System.out.print(average);
<identifier> expected

在此處輸入圖片說明

我在 Udacity Android 開發人員中進行了測試

public class MyCalculator {

    int input1 = 10;
    int input2 = 20;
    int input3 = 30;
    int input4 = 40;
    int input5 = 50;

    public float average() {
        // TODO: write java code to calculate the average for all input variables

         return 0;
    }
}

我必須給出答案才能繼續學習,我已經嘗試了一切,但它沒有接受答案。 預計該方法計算結果為 30.0 作為float

錯誤

|       public float average(( input1 + input2 + input3 + input4 + input5)/5 ) {
illegal start of type

|       System.out.print(average);
<identifier> expected

|       System.out.print(average);
<identifier> expected

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM