Click to See Complete Forum and Search --> : keep getting "Error: array required, but int found"


elie_commando
04-07-2007, 06:55 PM
keep getting that error. heres code

class sumarray
{

public static void main (String[] args)
{
System.out.print("Please enter the amount of Rows:");
int row = In.getInt();
System.out.print("Please enter the amount of Columns:");
int column = In.getInt();

int Array1[][];
Array1 = new int [row][column];
CalcArray (Array1 );


}



public static int [] CalcArray ( int [][]Array1 )
{
int b[] = new int [ Array1.length];
for (int r = 0 ; r < Array1.length ; r++)
{ int sum = 0;
for ( int c = 0 ; c < Array1.length[0]; c++)
{ sum = a [r][c] + sum ;
}
b[c] = sum ;
}
return b ;
}
}

elie_commando
04-08-2007, 04:50 PM
public static int [] CalcArray ( int [][]Array1 )
{
int b[] = new int [ Array1.length];
for (int r = 0 ; r < Array1.length ; r++)
{ int sum = 0;
for ( int c = 0 ; c < Array1.length[0]; c++)
{ sum = a [r][c] + sum ;
}
b[c] = sum ;
}
return b ;
}


keep getting errorr for that line

AlaNio
04-09-2007, 07:09 AM
Array1.length()

agent_x91
04-12-2007, 10:45 AM
That exception is thrown when you mismatch a variable type. You're trying to reference the length of the array as if it were an array itself, but it's just the length of the array, an int.

I think you probably mean the line to be

for ( int c = 0 ; c < Array1[0].length; c++)