Discharge of method
-
Method
sumCalculate
which summarises all the elements of the mass. I want him on the screen.main
but a mistake. How do you put it on the screen?main
? Trying to make a method of sums, it's on the screen.public static void main(String[] args) { int array[] = new int[] {10, -6, 5, 8, 58, 5};
System.out.println(sumCalculate(array, 0);); // Вот эта строка System.out.println(suma(5, 6));
}
public static void sumCalculate(int array[], int sum) {for (int i = 0; i < array.length; i++) { sum += array[i]; }
}
public static int suma(int a, int b) {
return a + b;
}
What am I doing wrong?
-
You have a method.
sumCalculate(int array[], int sum)
Nothing's coming back. You need to do something like that:public static int sumCalculate(int array[], int sum ){
for (int i = 0; i < array.length ; i++) { sum+=array[i]; } return sum;
}
Addition https://ru.stackoverflow.com/users/178988/qwertiy :
You've got an extra comma point in this line.
System.out.println(sumCalculate(array, 0););
It must be.
System.out.println(sumCalculate(array, 0));