Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package GenericCountMethodDouble_06;
- import java.util.ArrayList;
- import java.util.List;
- public class GenericBox<T extends Comparable<T>> {
- private List<T> box;
- public GenericBox() {
- this.box = new ArrayList<>();
- }
- public void add(T element) {
- this.box.add(element);
- }
- public long count(List<T> list, T strToCount) {
- long count = list.stream().filter(e -> e.compareTo(strToCount) > 0).count();
- return count;
- }
- }
- package GenericCountMethodDouble_06;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws NoSuchMethodException {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- GenericBox<Double> box = new GenericBox<>();
- List<Double> list = new ArrayList<>();
- double line;
- for (int i = 0; i < n; i++) {
- line = Double.parseDouble(scanner.nextLine());
- //box.add(line);
- list.add(line);
- }
- double strToCount = Double.parseDouble(scanner.nextLine());
- long count = box.count(list, strToCount);
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment