L'opérateur + est pas défini pour le type d'argument(s) Chaîne vide

public class chap7p4 {
    public static void main(String[] args) {
        int[] heights = { 33, 45, 23, 43, 48, 32, 35, 46, 48, 39, 41, };
        printArray(heights);
        System.out.println("Average is " + findAverage(heights)); //this is where I get the error
    }

    public static void printArray(int[] array) {
        for (int eachNum : array) {
            System.out.println(eachNum + "  ");
        }
    }

    public static void findAverage(int[] array) {
        int average = 0;
        int total = 0;
        for (int i = 0; i <= array.length; i++) {
            total = total + array[i];
        }
        average = total / array.length;
        System.out.println(average);

    }
}

J'obtiens cette erreur

"Exception in thread "main" java.lang.Error: Unresolved compilation problem: The operator + is undefined for the argument type(s) String, void"  
  • Il suffit de changer le type de retour de findAverage méthode de type int. Maintenant, le type de retour est void.
InformationsquelleAutor NedNarb | 2014-04-07