Hi,
I have the following code,it prints out a 5 by 5 matrix and puts "-" in each location.
I need to ask user for the number of * they like to put in the matrix and based on the number they enter replace a random "-" by a "*".
It would be great if you modify my code and help me:
Here is an example:
How many * you want in the matrix?
3
-*---
*----
----*
-----
-----
import java.io.*;
import java.util.*;
class TestRandomArray 1 {
private String [][] mBoard; // Good for a two-dimensional world
private int mDimension; // the size of the board
public TestRandomArray 1(int dimension) {
mDimension = dimension;
mBoard = new String[mDimension][mDimension];
for (int i = 0; i < mBoard.length; i++)
for (int j = 0; j < mBoard[i].length; j++)
mBoard[i][j] = "-";
}
public void display() {
for (int i = 0; i < mBoard.length; i++) {
for (int j = 0; j < mBoard[i].length; j++)
System.out.prin t(mBoard[i][j]);
System.out.prin tln();
}
}
public static void main(String[] argv) {
TestRandomArray 1 runATest = new TestRandomArray 1(5);
runATest.displa y();
}
}
I have the following code,it prints out a 5 by 5 matrix and puts "-" in each location.
I need to ask user for the number of * they like to put in the matrix and based on the number they enter replace a random "-" by a "*".
It would be great if you modify my code and help me:
Here is an example:
How many * you want in the matrix?
3
-*---
*----
----*
-----
-----
import java.io.*;
import java.util.*;
class TestRandomArray 1 {
private String [][] mBoard; // Good for a two-dimensional world
private int mDimension; // the size of the board
public TestRandomArray 1(int dimension) {
mDimension = dimension;
mBoard = new String[mDimension][mDimension];
for (int i = 0; i < mBoard.length; i++)
for (int j = 0; j < mBoard[i].length; j++)
mBoard[i][j] = "-";
}
public void display() {
for (int i = 0; i < mBoard.length; i++) {
for (int j = 0; j < mBoard[i].length; j++)
System.out.prin t(mBoard[i][j]);
System.out.prin tln();
}
}
public static void main(String[] argv) {
TestRandomArray 1 runATest = new TestRandomArray 1(5);
runATest.displa y();
}
}
Comment