I want to check whether my input array is consecutive or not?
In my application user can give input 1,6,7 then it returns false and if user input 3,4,5,6 then it returns true.
how can I do this in J2ME?
I want to check whether my input array is consecutive or not? In my
Share
The only way to do it is to write a loop that goes through each element in the array, starting from position zero to n-1 making sure that the value of the element at the next position (if any, you have to check boundaries all the time), is exactly the value of the element at the current position+1. The moment you find the condition to be false; you return false; if you don’t ever find a condition where the condition is not true, you can return true at the end of the loop.
That’s a very good exercise for you. Give it a try.