简体   繁体   English

尝试在 Java 中计算 5 个数字的平均值时出现“非法的类型开头”

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

I have test in Udacity Android developer我在 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;
    }
}

I must give answer to continue study and I have been try everything and it did not accept the answer.我必须给出答案才能继续学习,我已经尝试了一切,但它没有接受答案。 It is expected that the method calculates a result of 30.0 as a float .预计该方法计算结果为 30.0 作为float

error :错误

|       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

在此处输入图片说明

I have test in Udacity Android developer我在 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;
    }
}

I must give answer to continue study and I have been try everything and it did not accept the answer.我必须给出答案才能继续学习,我已经尝试了一切,但它没有接受答案。 It is expected that the method calculates a result of 30.0 as a float .预计该方法计算结果为 30.0 作为float

error :错误

|       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