-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongestword.java
More file actions
26 lines (24 loc) · 793 Bytes
/
longestword.java
File metadata and controls
26 lines (24 loc) · 793 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
/*
(c) Sergio Morales 2013
CodeEval Challenge: Longest Words
Date Solved: 12/22/13
*/
import java.io.*
public class Main {
public static void main (String[] args) throws IOException {
File file = new File( args[0]);
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
while( (line = in.readLine()) != null) {
String[] lineArray = line.split(" ");
Integer largestIndex = 0;
if(lineArray.length > 0) {
for(int i = 0; i < lineArray.length; ++i) {
if(lineArray[largestIndex].length() < lineArray[i].length())
largestIndex = i;
}
}
System.out.println(lineArray[largestIndex]);
}
}
}