I wrote a method that takes a int array as parameter then returns the largest entry of the array!
That’s what I did, but it didn’t work!
The only error is with largest();
The method largest(int[]) in the type Moon is not applicable for the arguments ()
What is the problem?
public class Moon {
public static void main(String[] args {
int array1[] = {5,10,15,20,25,30};
int max = largest();
System.out.println("the largest number is : " + max);
}
static int largest( int array1[] ){
int maxValue = 0;
for (int i = 0; i < array1.length; i++){
if (array1[i] > array1[maxValue]) maxValue = i;
}
return maxValue;
}
}
Call largest by passing the array as :
Initialize your
maxwithInteger.MIN_VALUEas:Change your comparison as: