Untitled

mail@pastecode.io avatar
unknown
plain_text
4 years ago
887 B
5
Indexable
Never
public class MinAndMaxValue {

    private Scanner scanner = new Scanner(System.in);
    private ArrayList<Integer> numbers = new ArrayList<>();

    public ArrayList<Integer> readNumbers() {
        System.out.println("Enter numbers: ");
        int number = scanner.nextInt();
        while (number != 999999) {
            numbers.add(number);
            number = scanner.nextInt();
        }
        Collections.sort(numbers);
        return numbers;
    }

    public int getMinValue() {
        return numbers.get(0);
    }

    public int getMaxValue() {
        return numbers.get(numbers.size() - 1);
    }

    public static void main(String[] args) {
        MinAndMaxValue minAndMaxValue = new MinAndMaxValue();
        minAndMaxValue.readNumbers();
        System.out.println(minAndMaxValue.getMinValue());
        System.out.println(minAndMaxValue.getMaxValue());
    }

}