Good evening, I have to fill in a grid that I created by adding 4 random letters in it. I don't know how to get started, I have an array [i=5][j=4] and I have to add to a random i and j a G and that 4 times. I am aware of having to use Math.random() as well as a while(x<4) but I don't know how to go about it.enter image description here
package tp1;
import java.util.*;
import java.lang.Math;
public class Joueur {
//attributs
String pseudo;
private char[][] grille;
private int nbreManches;
private int nbreObstacles;
//constructeurs
public Joueur(String valeur) {
nbreManches = 0;
nbreObstacles = 0;
grille = new char[5][4];
pseudo = valeur;
}
public Joueur() {
Scanner sc = new Scanner(System.in);
System.out.println("Quel est votre pseudo ?");
pseudo = sc.nextLine();
nbreManches = 0;
nbreObstacles = 0;
grille = new char[5][4];
}
public void afficher() {
grille = new char[5][4];
System.out.println("************************************");
System.out.println("Pseudo: " + pseudo);
System.out.println("Nombre de manches: " + nbreManches);
System.out.println("Nombres d'obstacles: " + nbreObstacles);
System.out.println();
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
System.out.print("|");
}
System.out.println("|");
}
System.out.println();
}
}
Aucun commentaire:
Enregistrer un commentaire