mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 17:29:31 +08:00
Add automatic linter (#4214)
This commit is contained in:
@ -66,10 +66,7 @@ public class TernarySearch implements SearchAlgorithm {
|
||||
Random r = new Random();
|
||||
int size = 100;
|
||||
int maxElement = 100000;
|
||||
Integer[] integers = Stream.generate(() -> r.nextInt(maxElement))
|
||||
.limit(size)
|
||||
.sorted()
|
||||
.toArray(Integer[] ::new);
|
||||
Integer[] integers = Stream.generate(() -> r.nextInt(maxElement)).limit(size).sorted().toArray(Integer[] ::new);
|
||||
|
||||
// the element that should be found
|
||||
Integer shouldBeFound = integers[r.nextInt(size - 1)];
|
||||
@ -77,11 +74,9 @@ public class TernarySearch implements SearchAlgorithm {
|
||||
TernarySearch search = new TernarySearch();
|
||||
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);
|
||||
|
||||
int toCheck = Arrays.binarySearch(integers, shouldBeFound);
|
||||
System.out.printf(
|
||||
"Found by system method at an index: %d. Is equal: %b%n", toCheck, toCheck == atIndex);
|
||||
System.out.printf("Found by system method at an index: %d. Is equal: %b%n", toCheck, toCheck == atIndex);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user