Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,28 @@
|
|||
import java.io.File;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class LongestStringChallenge {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String lines = "", longest = "";
|
||||
try (Scanner sc = new Scanner(new File("lines.txt"))) {
|
||||
while(sc.hasNext()) {
|
||||
String line = sc.nextLine();
|
||||
if (longer(longest, line))
|
||||
lines = longest = line;
|
||||
else if (!longer(line, longest))
|
||||
lines = lines.concat("\n").concat(line);
|
||||
}
|
||||
}
|
||||
System.out.println(lines);
|
||||
}
|
||||
|
||||
static boolean longer(String a, String b) {
|
||||
try {
|
||||
String dummy = a.substring(b.length());
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue