We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ae68c9d commit c7c8913Copy full SHA for c7c8913
longestword.java
@@ -0,0 +1,26 @@
1
+/*
2
+ (c) Sergio Morales 2013
3
+ CodeEval Challenge: Longest Words
4
+ Date Solved: 12/22/13
5
+*/
6
+
7
+import java.io.*
8
9
+public class Main {
10
+ public static void main (String[] args) throws IOException {
11
+ File file = new File( args[0]);
12
+ BufferedReader in = new BufferedReader(new FileReader(file));
13
+ String line;
14
+ while( (line = in.readLine()) != null) {
15
+ String[] lineArray = line.split(" ");
16
+ Integer largestIndex = 0;
17
+ if(lineArray.length > 0) {
18
+ for(int i = 0; i < lineArray.length; ++i) {
19
+ if(lineArray[largestIndex].length() < lineArray[i].length())
20
+ largestIndex = i;
21
+ }
22
23
+ System.out.println(lineArray[largestIndex]);
24
25
26
+}
0 commit comments