The operator + is undefined for the argument type(s) String, void

后端 未结 6 444
执念已碎
执念已碎 2021-01-29 13:41
public class chap7p4 {
    public static void main(String[] args) {
        int[] heights = { 33, 45, 23, 43, 48, 32, 35, 46, 48, 39, 41, };
        printArray(heights);         


        
6条回答
  •  旧时难觅i
    2021-01-29 14:09

    Change return type of your findAverage() method,

    i.e void findAverage to int findAverage

    public static int findAverage(int[] array) {
        int total = 0;
        for (int i = 0; i <= array.length; i++) {
            total = total + array[i];
        }
        return total / array.length;
    }
    

提交回复
热议问题