54 lines
1.3 KiB
Java
54 lines
1.3 KiB
Java
import java.util.Scanner;
|
|
/*
|
|
* Get list of ints
|
|
* first number is number of ints, never above 20
|
|
* print out all ints that are <= to last int
|
|
*
|
|
* input: 5 50 60 140 200 75 100
|
|
*
|
|
* output: 50 60 75
|
|
* for simplicity, all numbers should be followed by a space
|
|
* even the last one
|
|
*
|
|
* Use two methods:
|
|
*
|
|
* public static void getUserValues(int[] myArr, int arrSize, Scanner scnr)
|
|
*
|
|
* public static void outputIntsLessThanOrEqualToThreshold
|
|
* (int[] userValues, int userValsSize, int upperThreshold)
|
|
*/
|
|
|
|
public class outputBelowAmount{
|
|
|
|
public static void getUserValues(int[] myArr, int arrSize, Scanner scnr){
|
|
|
|
for (int i=0;i<arrSize;i++){
|
|
myArr[i] = scnr.nextInt();
|
|
}
|
|
myArr[arrSize+1] = scnr.nextInt();
|
|
|
|
outputIntsLessThanOrEqualToThreshold(myArr, arrSize, myArr[arrSize+1]);
|
|
}
|
|
|
|
public static void outputIntsLessThanOrEqualToThreshold
|
|
(int[] userValues, int userValsSize, int upperThreshold){
|
|
for(int i = 0; i<userValsSize; i++){
|
|
if (userValues[i] <= upperThreshold){
|
|
System.out.print(userValues[i] + " ");
|
|
}
|
|
}
|
|
System.out.println();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Scanner scnr = new Scanner(System.in);
|
|
|
|
int arrSize = scnr.nextInt();
|
|
int[] myArr = new int[20];
|
|
|
|
getUserValues(myArr, arrSize, scnr);
|
|
|
|
scnr.close();
|
|
}
|
|
}
|