Hallo, ich habe mich jetzt nach fast 10 Monaten wieder mit Arrays beschäftigt. Ich habe vor in einem 10ner Array Random Zahlen zu speichern, dass klappt auch soweit. nur am ende bekomme ich die weiter unten gepostete Fehlermeldung. erstmal hier der QuellCode:
Und hier die Fehlermeldung:
schonmal danke im vorraus
Java:
public class MainS {
public static void main(String[] args) {
int b = 8;
double[] d = new double[10];
while(d.length>0){
d[b]=Math.random();
System.out.println(d[b]);
b--;
}
}
}
Und hier die Fehlermeldung:
Code:
0.43998084855035635
0.02855768680741
0.7782371231028316
0.3892937530985784
0.5765046355064741
0.2652670599448055
0.2861093939033217
0.7396314542674579
0.3325728220049873
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at MainS.main(MainS.java:7)
schonmal danke im vorraus