mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-26 22:14:08 +08:00
@ -42,10 +42,8 @@ public class LinearSearch implements SearchAlgorithm {
|
||||
Random r = new Random();
|
||||
int size = 200;
|
||||
int maxElement = 100;
|
||||
Integer[] integers = Stream
|
||||
.generate(() -> r.nextInt(maxElement))
|
||||
.limit(size)
|
||||
.toArray(Integer[]::new);
|
||||
Integer[] integers
|
||||
= Stream.generate(() -> r.nextInt(maxElement)).limit(size).toArray(Integer[] ::new);
|
||||
|
||||
// the element that should be found
|
||||
Integer shouldBeFound = integers[r.nextInt(size - 1)];
|
||||
@ -53,12 +51,7 @@ public class LinearSearch implements SearchAlgorithm {
|
||||
LinearSearch search = new LinearSearch();
|
||||
int atIndex = search.find(integers, shouldBeFound);
|
||||
|
||||
System.out.printf(
|
||||
"Should be found: %d. Found %d at index %d. An array length %d%n",
|
||||
shouldBeFound,
|
||||
integers[atIndex],
|
||||
atIndex,
|
||||
size
|
||||
);
|
||||
System.out.printf("Should be found: %d. Found %d at index %d. An array length %d%n",
|
||||
shouldBeFound, integers[atIndex], atIndex, size);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user