aspose file tools*
The moose likes Beginning Java and the fly likes 2 Dimentional Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "2 Dimentional Array" Watch "2 Dimentional Array" New topic
Author

2 Dimentional Array

Arosha Perera
Greenhorn

Joined: Jan 17, 2010
Posts: 4
I need to know how to display some data like this.

" " 1 2 3 3 5
2 4 5 5 7 8
6 8 8 5 6 2
4 2 4 7 7 5
3 5 5 7 9 3

I know how to display data in a rectangular form using two for loops and using length attribute in arrays.
But I don't know how do I get the [0][0] th element empty. (I've represented the space like this " ")
I put NULL and tried but it didn't work.

Please be kind enough to help me. Thank you
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It depends on the data type. If the array is of primitive ints, say, you'd have to use a zero (0), not a null. If it's an array of objects, you can use null. But that won't necessarily display the way you want.

In order to get a space you'd need to either use a datatype that allowed spaces (like strings), or do a conversion during the display process (like null-to-space). I'm sure there are other solutions too.
Arosha Perera
Greenhorn

Joined: Jan 17, 2010
Posts: 4
ummm, I don't understand.

I am new to this language actually. Here's what i have been going through..



This is how I have learned, is there a way to put a empty space on [0][0] th?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
Arosha Perera
Greenhorn

Joined: Jan 17, 2010
Posts: 4

Please Excuse for the inconvenience ...Thank you
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You could also check for specific array indices, and it's the right one(s), display a space instead of the array value.
Arosha Perera
Greenhorn

Joined: Jan 17, 2010
Posts: 4

You mean like this?



Then it gives an error saying incompatible types
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Then that's probably not what I mean ;)

No, I meant during the looping/printing.
 
jQuery in Action, 2nd edition
 
subject: 2 Dimentional Array