i was trying to compare 2 variables in java but it gives me error and i cant figure it out.
I am reading matrix element then put it in temp then put that temp variable in an array. but it gives error when I try to put matrix element in temp and when I compare elements. error: array required, but float found. Anyone knows how to correct this ?
public float[] toSortedArray()
{
float b[];
float temp;
int index=0;
for(int i=1; i<=m; i++)
{
for(int j=1; j<=n; j++)
{
temp=a[m][n];
b[index++]=temp;
}
}
Arrays.sort(b);
System.out.print("[");
for(int z=0; z<(m*n)-1; z++)
{
System.out.print(b[z]+", ");
}
System.out.print(b[(m*n)-1]+"]\n");
}
a? It is never declared. Is it a field? Also please specify in which line the error occurs. Also use proper indentation. Finally, if you used an IDE such as Eclipse, you would quickly find most errors. Another one is that your method is missing a return statement.mandnare also not declared in this snippet. I also think you want to useiandjinside the loop to access the "matrix". There is a lot wrong with this code.