random
necesito que alguien me diga como ingresar ceros y unos aleatoriamente en un matriz
aqui esta lo que tendiar que hacer
public static void main(String[] args)
{
int [][] matriz = new int [algunvalor][algunvalor];
for(int i=0;i<algunvalor;i++)
{
for(int j=0;j<algunvalor;j++)
{
int numero = (int)Math.round((Math.random())*1); // esto me genera un aleatorio de 0 a 1
matriz[i][j]=numero
}
}
}
y ya lo tienes tambien hay un clase que te genera aleatorio de cualquier cosa que es la clase Random
public static void main(String[] args)
{
int [][] matriz = new int [algunvalor][algunvalor];
for(int i=0;i<algunvalor;i++)
{
for(int j=0;j<algunvalor;j++)
{
int numero = (int)Math.round((Math.random())*1); // esto me genera un aleatorio de 0 a 1
matriz[i][j]=numero
}
}
}
y ya lo tienes tambien hay un clase que te genera aleatorio de cualquier cosa que es la clase Random