Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Placing a Symbol in a Two-Dimensional Array

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 04-08-2010, 08:24 PM PM User | #1 gnardog New to the CF scene   Join Date: Apr 2010 Posts: 4 Thanks: 1 Thanked 0 Times in 0 Posts Placing a Symbol in a Two-Dimensional Array Hey all, I've hit a snag with a question and am hoping for a little guidance. In the question I am supposed to create a grid and have a user inputted character to fill up the space of the grid. ex. 4X4 with \$ \$\$\$\$ \$\$\$\$ \$\$\$\$ \$\$\$\$ Now, so far I've started out and think that I may be veering down the wrong path. I've created my methods and am not sure that the placeSymbol one is right. My code so far is: Code: ``` import java.util.*; public class Board { // variables int x; int y; String symbol1; String[][] twoDArray; // default constructor public Board() { x = 0; y = 0; symbol1 = ""; String[][] twoDArray = new String[100][100]; } // constructor public Board(int newRow, int newCol, String newSymbol1) { x = newRow; y = newCol; symbol1 = newSymbol1; String[][] twoDArray = new String[x][y]; } public int placeSymbol() { String[][] twoDArray = new String[x][y]; for(int i = 0; i < x; i++) { for(int j = 0; j < y; j++) { twoDArray[i][j] = symbol1; } } return 0; } public void printBoard(String[][] twoDArray) { for(int i = 0; i < x; i++) { for(int j = 0; j < y; j++) { System.out.println(); } System.out.println("" + twoDArray[x][y]); } System.out.println(); } public static void main(String[] args) { Board twoDArray; twoDArray = new Board(8, 8, M); twoDArray.printBoard(); } }``` My driver at the end isn't what the final product will be. I just quickly wrote it up to try and print out my board. Needless to say, there is an error there. It doesn't recognize the symbol 'M' in this case. This is why I know there are problems somewhere in my code but don't know where. I would be most thankful for any guidance. Thanks
 04-08-2010, 08:44 PM PM User | #2 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,599 Thanks: 4 Thanked 2,598 Times in 2,567 Posts The symbol problem is simple, M just hasn't been defined anywhere. If your intent is to use the character M, then wrap it in double quotes since the definition is for a string. Variable handling and method chaining is incorrect, declaring a String[][] inside a method gives it local scope and will be destroyed when the method completes. The consructors should be chained for simplicity, and a call to placeSymbol is missing. PrintBoard also needs correction from the looks of it, assuming it has a matrix type layout, println should only be called in the outer loop, and the inner should just need the character print. If you want to be lazy, String[][] isn't necessary at all. __________________ PHP Code: ``` header('HTTP/1.1 420 Enhance Your Calm');  ```
 Users who have thanked Fou-Lu for this post: gnardog (04-08-2010)
 04-08-2010, 09:07 PM PM User | #3 gnardog New to the CF scene   Join Date: Apr 2010 Posts: 4 Thanks: 1 Thanked 0 Times in 0 Posts I really appreciate your input. I'll give it a try and hope it works. Thanks!
 04-09-2010, 04:29 AM PM User | #4 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,599 Thanks: 4 Thanked 2,598 Times in 2,567 Posts np, post back if you have any other questions __________________ PHP Code: ``` header('HTTP/1.1 420 Enhance Your Calm');  ```

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 04:09 AM.