... i++) { // populate array
27            data[i] = 10 + generator.nextInt(90);
28         }
29
30         System.out.printf("%s%n%n", Arrays.toString(data)); // display array
31
32         // get input from user
33         System.out.print("Please enter an integer value (-1 to quit): ");
34         int searchInt = input.nextInt();
35
36         // repeatedly input an integer; -1 terminates the program
37         while (searchInt != -1) {
38            int position = linearSearch(data, searchInt); // perform search
39
40            if (position == -1) { // not found
41               System.out.printf("%d was not found%n%n", searchInt);
42            }
43            else { // found
44               System.out.printf("%d was found in position %d%n%n",
45                  searchInt, position);
46            }
47
48            // get input from user
49            System.out.print("Please enter an integer value (-1 to quit): ");
50 searchInt ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.