Commit 9ae3085f authored by hosein's avatar hosein

playground -> putRandom added!

parents
import java.util.Random;
public class PlayGround {
private int[][] ground;
int n, m;
PlayGround(int n, int m) {
this.n = n;
this.m = m;
ground = new int[n][m];
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
ground[i][j] = 0;
}
public void show() {
}
public void putRandom(int policeNumber) {
int i, j, k;
Random rand = new Random();
if (n * m > policeNumber)
for (k = 0; k < policeNumber; k++) {
i = rand.nextInt();
j = rand.nextInt();
if (ground[i][j] == 0)
ground[i][j] = 1;
else k--;
}
else System.out.println("Error!! police numbers are higher than n*m");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment