Hey all, another post from a greenhorn
i have the following program working but i'd like to send the array to another class, so that i can make some methods to manipulate the array
can some one tell me how to do it please. at the very bottom is a failed attempt.
public class Trial
{
public static void main (String[] args)
{
int [][] table = new int [7][7]; //initialises array
//---------------sets all values in array to -1---------
for (int row=0; row < table.length; row++)
{
for (int col=0; col<table[row].length; col++)
{ table[row][col] = -1;
}
}
//--------------input values into array-------------------
table[1][2]=2;
table[1][6]=3;
table[2][1]=2;
table[2][3]=5;
table[3][2]=5;
table[3][4]=9;
table[4][3]=9;
table[4][5]=1;
table[5][4]=1;
table[5][6]=8;
table[6][1]=3;
table[6][5]=8;
/*-----------------Prints out array -----------------------
for (int row=0; row < table.length; row++)
{
for (int col=0; col < table[row].length; col++)
System.out.print (table[row][col] + "\t");
System.out.println();
}
*/
}//closes public method
}//closes class
//-----------------------------------------this is my failed attempt
public class Contacts
{
private int [][] newtable = new int [7][7];
public Contacts (int a[][])
{
newtable[][]=a[][];
}
public String toString()
{
return newtable ;
}
}
any help would be greatly appreciated
Thanks
B
i have the following program working but i'd like to send the array to another class, so that i can make some methods to manipulate the array
can some one tell me how to do it please. at the very bottom is a failed attempt.
public class Trial
{
public static void main (String[] args)
{
int [][] table = new int [7][7]; //initialises array
//---------------sets all values in array to -1---------
for (int row=0; row < table.length; row++)
{
for (int col=0; col<table[row].length; col++)
{ table[row][col] = -1;
}
}
//--------------input values into array-------------------
table[1][2]=2;
table[1][6]=3;
table[2][1]=2;
table[2][3]=5;
table[3][2]=5;
table[3][4]=9;
table[4][3]=9;
table[4][5]=1;
table[5][4]=1;
table[5][6]=8;
table[6][1]=3;
table[6][5]=8;
/*-----------------Prints out array -----------------------
for (int row=0; row < table.length; row++)
{
for (int col=0; col < table[row].length; col++)
System.out.print (table[row][col] + "\t");
System.out.println();
}
*/
}//closes public method
}//closes class
//-----------------------------------------this is my failed attempt
public class Contacts
{
private int [][] newtable = new int [7][7];
public Contacts (int a[][])
{
newtable[][]=a[][];
}
public String toString()
{
return newtable ;
}
}
any help would be greatly appreciated
Thanks
B