• 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

Arrays

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code:
---------------------------------------------
class arrays{
public static void main(String[] args) {
int []a3,[]a4; // 1
int []a5,a6[]; // 2

}
}
----------------------------------------------
Why the statement at //1 is giving compilation error while the statement //2 has compiled.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both lines begin with int [] : You're trying try to declare variables of type int[].

[]a4 is not a valid variable name.

Line 2, a6 is ok because it's an int array of array...

The code could be "rewrited" like that, maybe it wille be more clear :

int a3[], []a4[];
int a5[], a6[][];
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's right.
Although
int []a5,a6[]; //2
passed complie,the result is not you want.

a6[] has change to a6[][].

The standard method is :

int[] a1,a2;
[ September 29, 2005: Message edited by: tian haitao ]
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic