Random de letras
Necesito hacer un random en una matriz de 8*8 pero con 63 casilleros llenos. En los casilleros deben ir letras (B o N).
Como lo hago??
Como lo hago??
Intenta creando un arreglo de tipo String con las letras del alfabeto y luego accedes a el segun un indice random.
String letra[]={"N";"B"}`;
Random r=new Random();
for (int i=0;i<8;i++)
{
for (int j=0;j<8;j++)
{
arreglo [i][j]=letra[r.nextInt(2)];
}
}
arreglo[8][8]=null;
Si se hace de otra manera te recomiendo que me cuentes.
String letra[]={"N";"B"}`;
Random r=new Random();
for (int i=0;i<8;i++)
{
for (int j=0;j<8;j++)
{
arreglo [i][j]=letra[r.nextInt(2)];
}
}
arreglo[8][8]=null;
Si se hace de otra manera te recomiendo que me cuentes.