Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 Dimentional Array

 
Arosha Perera
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please Excuse for the inconvenience ...Thank you
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You mean like this?



Then it gives an error saying incompatible types
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then that's probably not what I mean ;)

No, I meant during the looping/printing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic