Java to determine whether the values in an array are consecutive adjacent methods, java Array

Source: Internet
Author: User

Java to determine whether the values in an array are consecutive adjacent methods, java Array

* Determine whether the values in an array are consecutive adjacent.

* The following conditions are met:

* 1.0 is an exception, where 0 can be used with any character.
* 2. identical values are not repeated.
* 3. The array can be out of order.
* If the array does not contain 0, the maximum value-Minimum value = n (array length)-1 is met.
* When the array contains 0, the maximum value and minimum value are met. <n (array length)-1

* Therefore, when the maximum value-Minimum value> n (array length)-1, it must not be a consecutive adjacent array.

Package datastruct. usearray; public class JudgeAdjacent {private static boolean judege (int a []) {int min = Integer. MAX_VALUE; int max = Integer. MIN_VALUE; for (int I = 0; I <. length; I ++) {if (a [I]! = 0) {if (min> a [I]) {min = a [I];} if (max <a target = "_ blank">. length-1) {return false;} else {return true;} public static void main (String [] args) {int a [] =, 0, 0}; if (judege (a) {System. out. println ("this array is adjacent! ");} Else {System. out. println (" this array is not adjacent! ") ;}}</A>

The above java method to determine whether the values in an array are consecutively adjacent is all the content shared by the editor. I hope to give you a reference, and I hope you can provide more support to the customer's house.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.