473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Please help me to modify my code...

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 TestRandomArray1 {
private String [][] mBoard; // Good for a two-dimensional world
private int mDimension; // the size of the board
public TestRandomArray1(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.print(mBoard[i][j]);

System.out.println();
}

}
public static void main(String[] argv) {

TestRandomArray1 runATest = new TestRandomArray1(5);
runATest.display();
}
}
Nov 17 '09 #1
1 1510
Dököll
2,364 Expert 2GB
Thanks for posting your code... Please stay tuned for added support!
Nov 18 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: gene.ellis | last post by:
Hello everyone, I am really having a lot of trouble understanding the DOM and I doing something quite basic. I need to the DOM (in PHP 5) to modify an XML file. For example the XML basically...
35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
3
by: david | last post by:
I found my web.config file always in lock mode, when I tried to modify it, I ofter got "Can not create web.config" error. I had to reboot my machine, and before I accessed any site I can modify it....
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
2
by: RBCC | last post by:
I have a form with a 2 textboxes and a listbox, The data is read in by a file called "memberphones" The listnbox lists names in this way (lastname,first name) sorted by the last name. the...
0
by: Nitinkcv | last post by:
Hi, im getting the following error while trying to access any of my app's pages: Description: An error occurred during the parsing of a resource required to service this request. Please review...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
7
by: james | last post by:
Hi, I'm new to C++, and coming from a dynamically-typed language, I'm finding the data types difficult. My goal at the moment is to append a string that is typed as a command line argument into...
2
by: pinkf24 | last post by:
I cannot figure out how to add the following: Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform...
3
by: humsafar | last post by:
#include <iostream.h> #include <stdlib.h> #include <stdio.h> Class StudyProgram { Public: StudyProgram (); Void add StudyProgram (); Void edit StudyProgram (); Void delete StudyProgram ();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.