mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-25 05:22:39 +08:00
Format code with prettier (#3375)
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
package com.thealgorithms.searches;
|
||||
|
||||
import com.thealgorithms.devutils.searches.SearchAlgorithm;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Stream;
|
||||
import com.thealgorithms.devutils.searches.SearchAlgorithm;
|
||||
|
||||
/**
|
||||
* Linear search is the easiest search algorithm It works with sorted and
|
||||
@ -42,8 +42,10 @@ 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)];
|
||||
@ -52,8 +54,13 @@ public class LinearSearch implements SearchAlgorithm {
|
||||
int atIndex = search.find(integers, shouldBeFound);
|
||||
|
||||
System.out.println(
|
||||
String.format(
|
||||
"Should be found: %d. Found %d at index %d. An array length %d",
|
||||
shouldBeFound, integers[atIndex], atIndex, size));
|
||||
String.format(
|
||||
"Should be found: %d. Found %d at index %d. An array length %d",
|
||||
shouldBeFound,
|
||||
integers[atIndex],
|
||||
atIndex,
|
||||
size
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user