Answer:
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] arr = new int[5];
System.out.println("Enter values for integer list: ");
for (int i=0; i<5; i++){
arr[i] = input.nextInt();
}
System.out.print("Enter the threshold: ");
int t = input.nextInt();
outputIntsLessThanOrEqualToThreshold(arr, t);
}
public static void outputIntsLessThanOrEqualToThreshold(int[] arr, int threshold){
for (int x: arr){
if (x<threshold)
System.out.print(x + " ");
}
}
}
Explanation:
Create a function called outputIntsLessThanOrEqualToThreshold that takes two parameters, arr and threshold
Check each element in the arr. If they are smaller than the threshold, print the element
Inside the main:
Initialize the array with user inputs and get the threshold value
Call the outputIntsLessThanOrEqualToThreshold function with the entered array numbers and threshold value