I'm start to learn Java programming language and try to solve given task
I'm try to finish method to count occurrences in 2d array and output result in 1d
public static int[] histogram(int[][] a, int high) {
// Please write your code after this line
// init new array
int numOfRows = a.length;
int numOfCols = a[0].length;
int[] retVal = {};
//main loop
for (int o = 0; o < high; o++){
//System.out.println(o);
// go trough rows
for(int row = 0; row < numOfRows; row++ ){
// check for colum values
int count = 0;
for(int col = 0; col < numOfCols; col++ ){
if(a[row][col] = o ){
count++;
}
}
retVal[o] = count; // Fixed typo
}
}
return retVal;
}
this is my method
I'm using BlueJ IDE for compiling and when i compile i get error "Incompatible types " for this line
if(a[row][col] = o )
i don't get it why i get error, in my opininon a[row][col] is int type ? and o is int type too.
Thanks
ois a not a good choice of variable name? It looks far too much like0at a glance (in certain fonts).