-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimumElement.java
More file actions
39 lines (33 loc) · 1.02 KB
/
Copy pathMinimumElement.java
File metadata and controls
39 lines (33 loc) · 1.02 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.Scanner;
public class MinimumElement {
//METHOD TO PRINT ARRAY
static void printArray(int a[]){
for(int i=0; i<a.length; i++){
System.out.print(a[i] + " ");
}
System.out.println();
}
//METHOD TO FIND MINIMUM ELEMENT IN AN ARRAY
static void findMinimum(int a[]){
int min= a[0]; //ASSUMING a[0] IS THE MINIMUM
for(int i=1; i<a.length; i++){
if(a[i]<min){
min= a[i]; //UPDATING THE VALUE OF MINIMUM
}
}
System.out.println("Minimum= " + min);
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
//ARRAY SIZE AND ELEMENTS INPUT
System.out.print("Enter size of array: ");
int size= sc.nextInt();
int arr[]= new int[size];
System.out.print("Enter array elements: ");
for(int i=0; i<size; i++){
arr[i]= sc.nextInt();
}
printArray(arr);
findMinimum(arr);
}
}