forked from anupammathur19/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayMax.java
More file actions
51 lines (41 loc) · 1.19 KB
/
ArrayMax.java
File metadata and controls
51 lines (41 loc) · 1.19 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
40
41
42
43
44
45
46
47
48
49
50
51
class ArrayMax{
public static void main(String args[])
{
int a[]={10,2, 3, 4, 5};
int max=a[0],min=a[0];
for(int i=1;i<a.length;i++)
{ if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
class Simple{
public static void main(String args[]){
System.out.println("result of max and min calculated");
}
}
System.out.println("Max is"+max);
System.out.println("Min is"+min);
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class GFG {
// function to find minimum value in an unsorted
// list in Java using Collection
public static Integer findMin(List<Integer> list)
{
// check list is empty or not
if (list == null || list.size() == 0) {
return Integer.MAX_VALUE;
}
// create a new list to avoid modification
// in the original list
List<Integer> sortedlist = new ArrayList<>(list);
// sort list in natural order
Collections.sort(sortedlist);
// first element in the sorted list
// would be minimum
return sortedlist.get(0);
}