dimanche 17 octobre 2021

how do i populating an array with certain values in random spots JAVA

public static void main(String[] args) { int castleTiles[][] = new int[8][8];

    for(int i = 0; i < castleTiles.length; i++) {
        for(int j = 0; j < castleTiles[i].length; j++) {
            castleTiles[i][j] = 0;
        }
    }







    for(int i = 0; i < castleTiles.length; i++) {
        for(int j = 0; j < castleTiles[i].length; j++) {
            System.out.printf("%3d", castleTiles[i][j]);
        }
        System.out.println();
    }








}

I need to insert the number 1 5 times in 5 random different spots in the array and the number 2 once at a random spot in the array




Aucun commentaire:

Enregistrer un commentaire