Java:
public class Wuerfel
{
private int x, y, sum, za, s;
int[]z;
public Wuerfel(){
s=2;
z=new int[s];
za=0;
}
public void wuerfeln(int a, int b){
x=(int)(Math.random()*a)+b;
y=(int)(Math.random()*a)+b;
z[s]=x;z[s+1]=y;
s=s+2;
sum=x+y;
}
public int getWert(){
return sum;
}
public void zaehlen(){
for(int i=0;i<z.length;i++){
for(int j=0;j>z.length;i++){
if(z[i]==z[j]){
za++;
}
}if (z[i]!=0){
System.out.println("Die Zahl: "+z[i]+" kommt "+za+" mal vor");}
za=0;
}
}
}
Ich möchte zahlen, wie oft welche Zahl vorkommt und dann ausgeben - aber es kommt eine arrayoutofbound exception-wo liegen die Fehler?