Random numbers in an array, failed ... help me!!! | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
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. :)

9th Jun 2020, 11:28 PM
Curiosity Design
Curiosity Design - avatar
2 Respuestas
+ 3
Without show your code we can't help.
9th Jun 2020, 11:37 PM
A͢J
A͢J - avatar
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(""); }
9th Jun 2020, 11:41 PM
Curiosity Design
Curiosity Design - avatar