MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

arrays/ArraySearching.java:11–26  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

9
10public class ArraySearching {
11 public static void main(String[] args) {
12 Rand.Pint rand = new Rand.Pint();
13 int[] a = new Rand.Pint().array(25);
14 Arrays.sort(a);
15 show("Sorted array", a);
16 while(true) {
17 int r = rand.getAsInt();
18 int location = Arrays.binarySearch(a, r);
19 if(location >= 0) {
20 System.out.println(
21 "Location of " + r + " is " + location +
22 ", a[" + location + "] is " + a[location]);
23 break; // Out of while loop
24 }
25 }
26 }
27}
28/* Output:
29Sorted array: [125, 267, 635, 650, 1131, 1506, 1634,

Callers

nothing calls this directly

Calls 4

getAsIntMethod · 0.95
showMethod · 0.65
arrayMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected