public void ekstr() {
int max = tablica[0];
int maxIndex;
int min = tablica[0];
int minIndex;
for (int i = 0; i<tablica.length; i++) {
if (tablica[i]>max) {
max = tablica[i];
maxIndex = i;
}
if (tablica[i]<min) {
min = tablica[i];
minIndex = i;
}
}
System.out.println("Największą wartością jest " + max + " o indeksie " + maxIndex);
System.out.println("Najmniejszą wartością jest " + min + " o indeksie " + minIndex);
}
Jest to część kodu.
Wyświetla mi błąd:
java.lang.Error: Unresolved compilation problems:
The local variable maxIndex may not have been initialized
The local variable minIndex may not have been initialized
Jak to naprawić? Czuję, że jest to proste, ale nie mogę znaleźć błędu :D