1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| // Remplacement
public class remplacement{
public static final int MAX= 20 ;
public static void creation(int[][]mat){
int i,j;
int N=mat.length;
int M=mat[0].length;
for(i=0;i<N;i++){
for(j=0;j<M;j++){
System.out.print(mat[i][j]+"\t");
}
System.out.println();
}
}
public static void remplissagemat(int[][]mat,int n,int m,int A){
int i,j,cpt;
cpt=0;
while(cpt!=A){
i=(int) (Math.random()*((n-1)+1));
j=(int) (Math.random()*((m-1)+1));
if (mat[i][j]==0){
mat[i][j]=(int) (Math.random()*(MAX+1));
cpt=cpt+1;
}
}
}
//Programme principal.
public static void main(String [] args){
System.out.println("Taille du plateau en commencant par le nombre de lignes puis en second le nombre de colonnes");
int N=Clavier.readInt();
int M=Clavier.readInt();
System.out.println(" nombre d'objets ");
int A= Clavier.readInt(); // A correspond au nombre d'objets voulu.
int[][] mat1= new int[N][M];
System.out.println("Le plateau est le suivant :");
remplissagemat(mat1,N,M,A);
creation(mat1);
System.out.println("Nombres de cases à remplacer");
int nbre= Clavier.readInt();
}
} |
Partager