Answer:
package b4;
import java.util.Scanner;
public class TresholdValue {
public static void main(String[] args) {
// Create an object of the Scanner class to allow for user's input
Scanner input = new Scanner(System.in);
// Create a prompt to allow users to enter the set of integers
System.out.println("Please enter the set of integers, each followed by a space : ");
// Get the first integer from the set of inputs.
// Parse the input and convert it into an integer
// by using the Integer.parseInt() method.
// Store the result in an integer variable.
int first = Integer.parseInt(input.next());
// Create an integer array to hold the other numbers (first number excluded).
// The array should have a length equal in value to the first number in the set.
// This has been stored in a variable called "first".
int[] intarray = new int[first];
// Create a while loop that populate the intarray with the set of numbers
int i = 0;
while (input.hasNext() && i < intarray.length) {
intarray[i] = Integer.parseInt(input.next());
i++;
}
// Get the last value (threshold) from the intarray.
// The threshold value is the last element in the array.
int lastvalue = intarray[intarray.length - 1];
// Create a prompt before displaying the set of values that are less than or
// equal to the threshold value.
System.out.println("Values less than or equal to the threshold value (" + lastvalue + ") are : ");
// Create a loop to cycle through the array.
// At each cycle, the element is checked if or not it is less than or equal to
// the threshold value.
// If it is less than or equal to, the number is printed.
for (int j = 0; j < intarray.length - 1; j++) {
if (intarray[j] <= lastvalue) {
System.out.print(intarray[j] + " ");
}
}
// (Optional) Close the Scanner object to prevent resource leak
input.close();
}
}
Explanation:
The program has been written in Java. The source code file has been attached to this response. Please download it for better readability. The code contains comments explaining what goes on on each segment of the code.
Hope this helps!