• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multi Dim Array Question

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's safe to say we will probably be tested on this concept during the SCJP exam.
I'm not sure of the answer though....
Array 1:
int[][] arrayA = new int[5][10];
- Per my reading material...the first index operator represents five rows...second index represents 10 columns.
Array 2:
int[][] arrayA = { {1,2,3} , {4,5,6} , {7,8,9} };
- I don't understand the nested curly braces method...please help.
- Mike
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right,
1. 5 rows 10 columns
2. 3 rows 3 columns as in
row 0: 1,2,3
row 1: 4,5,6
row 2: 7,8,9
This is a short way of declaring and initializing an array in one shot !
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can see this array in this direction for you convienient.
int[][] arrayA = { {1,2,3} ,
{4,5,6} ,
{7,8,9} };
Now it become 3x3( rows by column ) matrix and in java it contain 0,1,2 rows as well as 0,1,2 column.

----> Row0 Column0 Row0 Column1 Row0 Column2
----> Row1 Column0 Row1 Column1 Row1 Column2
----> Row2 Column0 Row2 Column1 Row2 Column2


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic