Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I do this?

Status
Not open for further replies.

Sylvialn

IS-IT--Management
Dec 28, 2000
101
US
Hey all...I wanted to know if it is possible to reference back to an array declared in main by a public function?
example:
...main..{...string [][]board...}
then in a function I have:
...public...{...board[0][2] = ("Y")...} - here's where it gives me the error.

How can I change the original array in the main part from that function call?

Also, is there a way to copy a multidimensional array? (I'm taking a class and this assignment is kicking my b***!)

Thanks for the help!

Syl "Try everything at least once."
 
Hi,

The String-array is not necessary initialized in your second function, so you have to know the initial size of the array you receive as a parameter.

However you _can't_ do this in your second method if you want to use the same reference:
String[][] board = new String[1][3];

Here is a one example how to use the same String-array reference in two separate methods:
_________________________________

public class Ref
{
public static void main(String[] argv)
{
if(argv.length < 3)
argv = new String[3];

alter(argv);
System.out.println(argv[0]);
System.out.println(argv[1]);
System.out.println(argv[2]);
}

public static void alter(String[] str)
{
str[0] = &quot;foo&quot;;
str[1] = &quot;bar&quot;;
str[2] = &quot;foobar&quot;;
}
}

*Prints: 'foo bar foobar' in main

I hope that helped,
-Vepo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top