简体   繁体   English

如何检查输入数组是否连续?

[英]How to check whether input array is in consecutive manner or not?

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. 在我的应用程序中,用户可以输入1,6,7,然后返回false,如果用户输入3,4,5,6,则返回true。
how can I do this in J2ME? 如何在J2ME中做到这一点?

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. 唯一的方法是编写一个遍历数组中每个元素的循环,从位置0开始到n-1,确保该元素在下一个位置的值(如果有,则必须检查所有边界)。时间),即该元素在当前位置+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. 如果您找不到条件不成立的条件,则可以在循环结束时返回true。

That's a very good exercise for you. 这对您来说是一个很好的练习。 Give it a try. 试试看。

遍历数组,查看下一个元素(如果存在)是否比上一个元素(如果存在)正好大1,如果不返回false,则返回true;否则返回true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM