How to realize dichotomy search by java
Editor to share with you how to achieve java dichotomy search, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Dichotomy search
/ / the premise must be under orderly conditions
Example: first take a look at the small to big
Import java.util.Scanner;public class T07 {public static void main (String [] args) {Scanner s = new Scanner (System.in); int a = s.nextInt (); int [] arr=new int [] {1, 2, 3, 4, 7, 8, 9, 10}; int left=0; int right= arr.length-1; boolean is=true; while (lefta) {right=average-1 } else if (left= average = arr [average]) {System.out.println ("found, subscript:" + average); is=false;} else {left= average + 1 if (left==right) {/ / System.out.println ("not found"); / / is=false }} if (is) {System.out.println ("I'm sorry I can't find it");} above is all the content of the article "how to find java by dichotomy". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!