Pinkman4242
Neues Mitglied
Hey, bin Anfänger und wollte eine automatische Funktion coden. Das Array soll von selbst sich den Größten Int wert raus suchen und wieder geben. Bekomme aber immer eine Fehlermeldung:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 12 out of bounds for length 12
at List.main(List.java:15)
Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 12 out of bounds for length 12
at List.main(List.java:15)
Code:
Java:
public class List {
public static void main(String[] args) {
int[] liste = {213, 123, 21, 231, 313, 313, 334, 231, 412, 213, 231, 880};
int i = 0;
int antwort = 0;
int listenmax = 0;
for (int arrayanzahl = 0; arrayanzahl < liste.length; arrayanzahl++) {
i++;
listenmax = liste[i];
if (listenmax >= antwort) {
listenmax = antwort;
}
}
System.out.println("Die Größte Zahl in der Liste ist " + antwort + " groß");
}
}
Zuletzt bearbeitet von einem Moderator: