Results 1 to 12 of 12
- 09-09-2011, 09:20 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 14
- Rep Power
- 0
- 09-09-2011, 09:43 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Re: 2D array
I'd do it like this:
kind regards,Java Code:char[][] dim2array= { "xxxxx".toCharArray(), "x x".toCharArray(), "x x x".toCharArray(), "x x".toCharArray(), "xxxxx".toCharArray() };
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-09-2011, 09:45 PM #3
Re: 2D array
What data type is the array?
What do the empty slots represent if the array is of primitives?
Go to this site and Find Arrays : Trail: Learning the Java Language: Table of Contents (The Java™ Tutorials)
for a tutorial about using arrays in java.
- 09-09-2011, 10:40 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 14
- Rep Power
- 0
- 09-09-2011, 10:49 PM #5
Re: 2D array
What data type is the array?
What goes in the empty elements?
To define a two dim array:
<datatype>[][] twoDim = new <datatype>[rows][columns];
Then go thru the rows and columns to set the values.
Or another way is to only define the rows initially and define the columns later:
<datatype>[][] twoDim = new <datatype>[rows][];
twoDim[i] = new <datatype>[columns for this row]; // assign the columns for this row
- 09-09-2011, 10:51 PM #6
Member
- Join Date
- Apr 2011
- Posts
- 14
- Rep Power
- 0
Re: 2D array
its suppose to be characters, first and last row are empty as well as first and last column.
- 09-09-2011, 10:54 PM #7
Re: 2D array
There is no such thing as an empty element. The element has some value like null or 0.
The empty elements would be past the end of the array, like the 11th element in an 10 element array.
Or I suppose a String of length 0 could be considered empty, but it's still a String.
- 09-09-2011, 11:06 PM #8
Member
- Join Date
- Apr 2011
- Posts
- 14
- Rep Power
- 0
Re: 2D array
ok so lets say it is null,
so how do i do it so it would exactly show as the picture i inserted above, without the grid lines of course
- 09-09-2011, 11:08 PM #9
Re: 2D array
We've given some examples. What have you tried?
There are no null char values. For null, you will have to have a class as the data type of the array.
- 09-09-2011, 11:31 PM #10
Member
- Join Date
- Apr 2011
- Posts
- 14
- Rep Power
- 0
Re: 2D array
please just show me how i can print the above image in 2d array.
- 09-09-2011, 11:35 PM #11
Re: 2D array
See the Arrays toString() method for an easy way to display the contents of an array.
If you want to control the output use a nested loop: (outer by row; inner by column) and use the print method for the columns in a row and the println once at the end of a row.
- 09-10-2011, 08:52 AM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Display Array on another class after extracting from txt file and into array problem
By jonathan920 in forum NetBeansReplies: 0Last Post: 05-12-2011, 07:04 PM -
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
Array length and printing out uninitialized array.
By nicolek808 in forum New To JavaReplies: 4Last Post: 09-10-2009, 09:12 AM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks