• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

array indexing in 2d array...???

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.

please explain how we have used index here....like row and column....i know about this we have an array, a, with two rows and four columns.

// Two rows and four columns.

but what about the 1. as in that we don't have actual index provided....what will be the index in that.....
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java, a two-dimensional array is really an array of arrays.

Taking your first example, let's imagine that we can write X to mean int[]. Then it translates as:(Where x1 = {1,0,0} etc).

So now you can see the board array has three elements, with the indices 0-2. board[2] = x3, for instance. But each of those elements is an array that also has three elements. So you've got three rows and three columns. You didn't need to specify the size because you're giving the exact contents, so the size can be easily worked out from that.

In this particular example, all the arrays contained in the board array have the samer length, and that's also what will happen in your second example. But you also ought to know that they don't have to be the same. The following is also valid:Here the first row has three columns, the second has two, and the third has 5.
 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hennry Smith wrote:1.

please explain how we have used index here....like row and column....i know about this we have an array, a, with two rows and four columns.

// Two rows and four columns.

but what about the 1. as in that we don't have actual index provided....what will be the index in that.....



You can think about this as Matrix also

100
010
121

1 is in 0 row 0 column position
0 is in 0 row 1 coloumnposition
etc...
 
My, my, aren't you a big fella. Here, have a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic