I want to check if all similar integers are grouped in an array or list.
{2, 2, 5, 5, 5, 1, 7, 7, 5, 7}must give false. I {2, 2, 5, 5, 5, 1, 7, 7, 7}have to give it so far true. This is what I have and prints truewhen it should be false:
public class testing1 {
public static void main(String[] args){
int [] x = {2, 2, 5, 5, 5, 1, 7, 7, 5, 7};
System.out.println(isGrouped(x));
}
public static boolean isGrouped(int[] x){
for(int i = 0; i < x.length; i++){
for(int j = i + 1; j < x.length; j++){
if(x[i] == x[j])
return true;
}
}
return false;
}
}
source
share