Here is the code snippet that I am working on and my goal is to find the largest value from the list using predefined Java methods.
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter a list of integers: ");
int array[] = new int[10];
for (int i = 0; i < array.length; i++) {
array[i] = s.nextInt();
}
for (int j = 0; j < array.length; j++) {
if (j < array.length) {
int maximum = Math.max(array[j], array[j + 1]);
}
}
System.out.println("Largest number of the list: " + maximum);
}
}
The error that I am getting is the following:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
maximum cannot be resolved to a variable
How can I resolve this issue?