Define a method in which, given a two-dimensional array, evaluates if it has at least two identical rows
I've tried to come up with an algorithm to do it but I didn't go very far. This is what I got:
public static boolean righeUguali(int[][] a){
boolean rUguali=false;
for(int i=0; i<a.length; i++)
for(int j=0; i<a[i].length; j++)
if(Arrays.equals(a[i],a[j]))
rUguali = true;
return rUguali;
could you help me fix this code?
j with i+1Here the modified code:
public static boolean righeUguali(int[][] a){
for(int i=0; i<a.length-1; i++)
for(int j=i+1; i<a.length; j++)
if(Arrays.equals(a[i],a[j]))
return true;
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With