Snippets

Il'ya Tomberg Searh minimim number(int)

Created by Il'ya Tomberg
import java.util.ArrayList;
import java.util.Scanner;

public class SearchMinInt {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        boolean end = false;
        ArrayList<Integer> numbers = new ArrayList<>();
        while (!end){
            if (sc.hasNextInt()){
                numbers.add(sc.nextInt());
            } else if (sc.nextLine().equals("min")) {
                end = true;
                System.out.println("Минимальное число: " + min(numbers));
            }

        }
    }
    public static int min(ArrayList<Integer> numbers) {
        int min = numbers.get(0);
        for (int i = 1; i < numbers.size(); i++) {
            if (numbers.get(i) < min) min = numbers.get(i);
        }
        return min;
    }
}

Comments (0)