Hallo ich muss für meine Ausbildung einen Insert Sort schreiben finde den fehler aber nicht. Es ist sehr wichtig.
Der Fehler lauted: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:-1
at Insert.main(Insert.java:22)
Der Fehler lauted: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:-1
at Insert.main(Insert.java:22)
Java:
public class Insert {
public static void main(String[] args) {
int element ;
int i;
int j;
int[]z = {5,3,1,2,-1,-1};
for(i = 1; i <z.length; i++)
{
element = z[i];
for(j=i-1; j>=0; j--);
{
if(z[j]>element)
{
z[j+1]=z[j];
}
else
break;
}
z[j+1]=element;
}
do
{
i = 0;
System.out.println (z[i]);
i = i + 1;
} while
(i < 6);
Zuletzt bearbeitet: