• 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

Array declaration

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Choose correct declarations of two dimensional String array

A. String[][] a = String[20][20]
B. String[][] a = new String[20,20]
C. String[][] a = new String[20][20]
D. String a[][] = new String[20][20]
E. String[] a[] = new String[20][20]
I think answer is C, D, E
Any takers.........

[This message has been edited by sdev (edited August 14, 2000).]
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


A. String[][] a = String[20][20]
B. String[][] a = new String[20,20]
C. String[][] a = new String[20][20]
D. String a[][] = new String[20][20]
E. String[] a[] = new String[20]20]
I think answer is C, D, E


The answer is C,D
E. String[] a[] = new String[20]20]
I don't think this is correct. I hope now you understood why it is wrong? Am I right?
Nirmala
 
sasank manohar
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nirmala,
Actually the statment gets executed without any error. And I think its correct.
But I just wanted to make sure my answer.

Can you just try executing this statement...
Please reply..
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think String[] a[] = new String[20][20];is correct because
the left hand side is saying:
String a is going to be a array of strings with each individual
element being an array. ie, a is an array of arrays;
chengx
 
Nirmala
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Sdev,
E. String[] a[] = new String[20]20]
I am sure this statement is not syntactically correct.
I have JBuilder 2.0 and it does not compile this.


Hi,
I think String[] a[] = new String[20][20];is correct because
the left hand side is saying:
String a is going to be a array of strings with each individual
element being an array. ie, a is an array of arrays;
chengx



Please chengx ,the statement that you said is correct is different one from mine.
Nirmala
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks, that compiled and ran fine for me. I am pretty sure it doesn't make a difference where the braces of the left occur as long as they are to the right of the datatype. I agree that it doesn't look very pretty and most people shy away from writing the declaration that way, but it is possible.
Hope that helps.
Paul
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys !
String []a[] = new String[20]20];

it gives me a compile error.. it says expected ';' in the second 20... Lemme clear, whether it's right or wrong....whether it varies frm compiler to compiler i gues i've 1.2 i think.. how to check what compile we 've i downloaded long back now i donno what version i'm having..
thnx for all help..
rajan
 
sasank manohar
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The statement is String[] a[]=new String[20][20];
not String []a[] = new String[20]20];// you missed 1 square
// bracket in the statement on the right side.

Originally posted by Rajan Narayanan:
Hi guys !
String []a[] = new String[20]20];

it gives me a compile error.. it says expected ';' in the second 20... Lemme clear, whether it's right or wrong....whether it varies frm compiler to compiler i gues i've 1.2 i think.. how to check what compile we 've i downloaded long back now i donno what version i'm having..
thnx for all help..
rajan


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