-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathThirdGreatest.java
More file actions
35 lines (26 loc) · 864 Bytes
/
Copy pathThirdGreatest.java
File metadata and controls
35 lines (26 loc) · 864 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
32
33
34
35
import java.util.*;
import java.io.*;
class Challenge {
public static String ArrayChallenge(String[] strArr) {
// code goes here
int[] array= new int[strArr.length];
int desiredLength=0;
String result="";
for(int i=0;i< strArr.length;i++){
array[i]= strArr[i].length();
}
Arrays.sort(array);
desiredLength=array[strArr.length-3];
for(int i= 0;i< strArr.length;i++){
if(strArr[i].length()==desiredLength){
result= strArr[i];
}
}
return result;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(ArrayChallenge(new String[] {"hello", "world", "after", "all"}));
}
}