I want to check if numbers in an arraylist are sequential. The number in array start with 1, and for the next should be 2, 3, and 4. This means that every next element is 1 larger than the previous.
public static void main(String[]args){
ArrayList<Integer> array = new ArrayList<Integer>();
array.add(1); array.add(3);
for (int i = 0; i < array.size(); i++){
if(logic here){
System.out.println(not sequence);
}else{
system.out.pritnln(sequence);
}
}
}
For this case, after 1 it should be 2, but there is 3. how can i implement the correct logic for this case? Thank you!!!