Skip to content

Commit ce525a9

Browse files
authored
Merge pull request #1 from MerinAlex23/MerinBranch
Create largestInArray.java
2 parents 3d104dc + e171c43 commit ce525a9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.ArrayList;
2+
import java.util.Collections;
3+
import java.util.Scanner;
4+
5+
public class largestInArray {
6+
7+
public static void main(String[] args) {
8+
// TODO Auto-generated method stub
9+
Scanner sc=new Scanner(System.in);
10+
ArrayList<Integer>li=new ArrayList<Integer>();
11+
System.out.println("no of elements");
12+
int n=sc.nextInt();
13+
14+
System.out.println("enetre array elements");
15+
for(int i=0;i<n;i++) {
16+
li.add(sc.nextInt());
17+
18+
}
19+
Collections.sort(li);
20+
System.out.println(li);
21+
System.out.println("enter which largestt element");
22+
int j=sc.nextInt();
23+
System.out.println(li.get(n-j));
24+
25+
}
26+
27+
}

0 commit comments

Comments
 (0)