Help coderanch get a
new server
by contributing to the fundraiser
  • 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

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's something I'm stumbling with



and the command-line invocation,
java CommandArgsThree 1 2 3
Q-->what is the result?

I'm not being able to interpret this code.
from intial feedbacks this is how I'm seeing the picture


each element in "argcopy" contains an array of 2 elements as shown
above 'argcopy' [ could not draw the linking lines properly....too painful ]
considering 'x = argCopy[0].length;' should be 3 , what is happening with

System.out.print(" " + argCopy[0][y]); // in terms of the boxes I have
drawn. If at all I have drawn them in the proper way.

TIA

( tags added and an attempt to format the code)
[ November 10, 2004: Message edited by: Barry Gaunt ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
5. argCopy[0] = args;

after this line argCopy[0] will be refering to the array of length 3 which is reffered to by arg.

before line 5
argcopy[0]-------->[null] [null] /*an array of length 2 whose elements are initialized to null.*/


after line 5.
argcopy[0]-------->["1"] ["2"] ["3"]//an array of length 3 .

[ November 10, 2004: Message edited by: Atul Chandran ]

[ November 10, 2004: Message edited by: Atul Chandran ]
[ November 10, 2004: Message edited by: Atul Chandran ]
 
Netty poestel
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Atul Chandran:
5. argCopy[0] = args;

after this line argCopy[0] will be refering to a new array of length 3.

before line 5
argcopy[0]-------->[0] [0] //an array of length 2 initialized to 0.


after line 5.
argcopy[0]-------->[1] [2] [3]//an array of length 3.

[ November 10, 2004: Message edited by: Atul Chandran ]

[ November 10, 2004: Message edited by: Atul Chandran ]




Howdy..

(i)
"before line 5 argcopy[0]-------->[0] [0] an array of length 2 initialized to 0."

since it's a String array, shouldn't that be initialized as a null ?


(ii)
"after this line argCopy[0] will be refering to a new array of length 3."

would this mean that argcopy is now referring 'also' to a 3rd new array. ? so are the original 2 are stll connected at this point ?

Thx.
 
Atul Chandran
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry my mistake ...you are right..I have editided my post...Didn't look at the code closely.
 
Did you miss me? Did you miss this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic