-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimumElement.java
More file actions
40 lines (35 loc) · 1.17 KB
/
MinimumElement.java
File metadata and controls
40 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.*;
public class MinimumElement {
private static int readInteger(){
try (Scanner sc = new Scanner(System.in)) {
return sc.nextInt();
}}
private static int[] readElements(int n){
try (Scanner sc = new Scanner(System.in)) {
int[] array = new int[n];
for(int i=0;i<n;i++){
System.out.println("Number: ");
int num = sc.nextInt();
sc.nextLine();
array[i]=num;
}
return array;
}
}
private static int findMin(int[] a){
int min = Integer.MAX_VALUE;
for(int i=0;i<a.length;i++){
if(a[i]<min)
min=a[i];
}
return min;
}
public static void main(String[] args){
System.out.println("Hi! please enter an amount of numbers. You will then enter those numbers one by one and I will find the minimun value!");
System.out.println("How many numbers would you like to evaluate?");
int length=readInteger();
int[] array=readElements(length);
int min=findMin(array);
System.out.printf("Min: "+min);
}
}