I am creating a little program to find the largest number in an array. The problem is that when I call my function to check for the largest value it says that it expects a class, but that doesn't really make sense for me.
Sorry for my beginner question, but I couldn't find any help elsewhere.
Here is my current code:
package challenge;
import java.util.Scanner;
class Challenge {
public static int findMax(int arr[], int size) {
int maxValue = arr[0];
for(int i = 0; i < size; i++) {
if(arr[i] > maxValue) {
maxValue = arr[i];
}
}
return maxValue;
}
public static void main(String[] args) {
int numbers[] = new int[300];
System.out.println("Enter data: ");
Scanner scan = new Scanner(System.in);
for(int i = 0; i < 300; i++) {
int input = scan.nextInt();
numbers[i] += input;
}
int maxValue = findMax(numbers[], numbers.length);
System.out.println("The largest value in the array: " + maxValue);
}
}
Thank you and have a nice day.
int[] numbers(instead ofint numbers[]), as that cleary conveys that you've got a variable namednumbersof typeint[](integer-array). That does not solve your problem, but you'll be more likely to spot the error once you changed that ;)