task_id
stringclasses
1 value
entry_point
stringclasses
1 value
prompt
stringclasses
1 value
canonical_solution
stringclasses
1 value
suffix
stringclasses
1 value
test
stringclasses
1 value
SingleLineInfilling/HumanEval/Java/L0
has_close_elements
import java.util.List; public class Solution { public static boolean hasCloseElements(List<Double> numbers, double threshold) { // Your solution goes here
for (int i = 0; i < numbers.size(); i++) {
for (int j = i + 1; j < numbers.size(); j++) { if (Math.abs(numbers.get(i) - numbers.get(j)) < threshold) { return true; } } } return false; } }
public static void main(String[] args) { List<Double> test1 = Arrays.asList(1.0, 2.0, 3.9, 4.0, 5.0, 2.2); assert hasCloseElements(test1, 0.3) == true; List<Double> test2 = Arrays.asList(1.0, 2.0, 3.9, 4.0, 5.0, 2.2); assert hasCloseElements(test2, 0.05) == false; // Additional test cases with assertions }