aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arrays" Watch "Arrays" New topic
Author

Arrays

Shiva Arava
Greenhorn

Joined: Feb 26, 2002
Posts: 2
Can I know why the value of the zeroth element of myValue is 3, and not 2, because the modifyIt method just increments it.
public class JavaTest
{
public static void main(java.lang.String[] args)
{
JavaTest test = new JavaTest();
int[] myValue = {1};
System.out.println("myValue contains " + myValue[0]);

test.modifyIt(myValue);
System.out.println("myValue now contains " + myValue[0]);
}
public void modifyIt(int[] value)
{
value[0]++;
System.out.println(value[0]);
}
}

Output : myValue contains 1
: myValue now contains 3
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Are you sure the code you've posted here is the same code you're running. I just ran it and got this:

This is just what I'd expect.
Corey


SCJP Tipline, etc.
Shiva Arava
Greenhorn

Joined: Feb 26, 2002
Posts: 2
I checked the program, I get the value of myValue[0] as 2.
Thanks
Shiva
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays