0
Random numbers in an array, failed ... help me!!!
Someone help me with this problem ... I can't fill an array with random numbers WITHOUT repeating, I'm not using methods or anything like that, thanks. :)
4 Answers
+ 3
Without show your code we can't help.
0
int aleatorio;
int matriz[][] = new int[3][3];
int f,c;
for(f = 0; f < matriz.length; f++){
for(c = 0; c < matriz.length; c++){
aleatorio = (int)((Math.random()*75)+1);
while(aleatorio != matriz[f][c]){
if(aleatorio == matriz[f][c]){
matriz[f][c] = aleatorio = (int)((Math.random()*75)+1);
}
else{
matriz[f][c ] = matriz[f][c];
}
}
}
}
for(f = 0; f < matriz.length; f++){
for(c = 0; c < matriz.length; c++){
System.out.print("[ " + matriz[f][c] + " ]");
}
System.out.println("");
}