As the title say i want to populate a 2d array with random strings, in this case "_" and "W", and i made both the 2d array and a random string generator but i can find a away to populate the array created with the string generated
import java.security.SecureRandom;
public class Array_Generator {
public static void main(String[] args) {
int row = 5;
int col = 5;
int[][] grid = new int[row][col];
String AB = "_W";
SecureRandom rnd = new SecureRandom();
for( int i = 0; i < grid.length; i++ ) {
StringBuilder sb = new StringBuilder(row);
sb.append( AB.charAt( rnd.nextInt(AB.length()) ) );
sb.toString();
for (int j = 0; j < grid[i].length; j++) {
sb.append( AB.charAt( rnd.nextInt(AB.length()) ) );
sb.toString();
}
}
Any help would be apreciated.
Aucun commentaire:
Enregistrer un commentaire