I'm stuck on this method.
public class Duplicate{
public static boolean extra(int [][] grid)
{
for(int i = 0; i < grid.length; i++)
for(int j = 0; j < grid[i].length-1; j++)
if(grid[i][j] == grid[i][j+1])
{
System.out.println(grid[i][j]);
return true;
}
return false;
}
public static void main(String[] args){
int [][] grades = {{3,5,8,7},
{2,1,11,4},
{13,20,10,6},
{7,0,12,15}
};
System.out.print(extra(grades));
}
}
I want to find if there are any duplicated ints in the array. return true if there is and the int that is duplicated. My method keeps coming out FALSE. what am I doing wrong? Any help would be appreciated. Please and thank you.