Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package svephoto;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Numbers {
- public static void main(String[] args) {
- Scanner Input = new Scanner(System.in);
- List<Integer> Sequence = Arrays.stream(Input.nextLine().split(" ")).map(Integer::parseInt).sorted(Collections.reverseOrder()).collect(Collectors.toList());
- int totalSum = 0;
- for (Integer currentInteger : Sequence) {
- totalSum += currentInteger;
- }
- double averageValue = totalSum * 1.0 / Sequence.size();
- List<Integer> topFiveNumbers = new ArrayList<>();
- for (Integer currentNumber : Sequence) {
- if (currentNumber > averageValue) {
- topFiveNumbers.add(currentNumber);
- }
- }
- if (topFiveNumbers.isEmpty()) {
- System.out.println("No");
- } else if (topFiveNumbers.size() < 5) {
- for (Integer number : topFiveNumbers) {
- System.out.printf("%d ", number);
- }
- } else {
- topFiveNumbers = topFiveNumbers.stream().limit(5).collect(Collectors.toList());
- for (Integer number : topFiveNumbers) {
- System.out.printf("%d ", number);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement