Add lab
This commit is contained in:
parent
d114f8c9ec
commit
63531fb46c
53
output-below-amount/outputBelowAmount.java
Normal file
53
output-below-amount/outputBelowAmount.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user