2 condition:
The program should display 5 numbers, each on a new line.
3 condition:
The output must contain the same numbers that were entered (order is not important).
package com.codegym.task.task06.task0622;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/*
Ascending numbers
*/
public class Solution {
private static int count = 0;
public static void main(String[] args) throws Exception {
//reading
List<Integer> il = readInts(5);
//sorting
il.sort(Comparator.comparingInt(Integer::intValue));
//displaying
il.forEach(System.out :: println);
}
public static List<Integer> readInts(int count) {
List<Integer> intList = new ArrayList<>(count);
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
while (Solution.count < count) {
intList.add(Solution.count, Integer.parseInt(reader.readLine()));
Solution.count++;
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return intList;
}
}