-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxarr.java
More file actions
31 lines (29 loc) · 929 Bytes
/
Copy pathmaxarr.java
File metadata and controls
31 lines (29 loc) · 929 Bytes
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
import java.util.*;
public class maxarr {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n;
System.out.println("enter the number of elements in array :");
n = s.nextInt();
int ar[] = new int[n];
ArrayList<Integer> list = new ArrayList<>();
int flag = 0;
for (int i = 0; i < n; i++) {
System.out.println("enter the elements in array :"+(i+1));
ar[i] = s.nextInt();
}
for (int i = 0; i < ar.length; i++) {
int x = ar[i];
flag = 0;
for (int j = i + 1; j < ar.length; j++) {
if (ar[i] < ar[j]) {
flag = 1;
}
}
if (flag == 0) {
list.add(ar[i]);
}
}
System.out.print(list);
}
}