Snippets

Il'ya Tomberg Searh minimim number(int)

Created by Ilya Tomberg

File SearchMinInt.java Added

  • Ignore whitespace
  • Hide word diff
+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;
+    }
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.