Print required output in Java : <p>I have requirement as below on array:</p>

<p>Input   [1,2,5,7]                 Output  [1,5,7]</p>

<p>Input   [4,5,6,8]                 Output   [4,8]</p>

<p>Input   [1,2,3,9,10]              Output   [1,9]</p>

<p>Means if the next number is in sequence the take the first value in output, otherwise take all the values in output.</p>

<p>Thanks.</p>
