-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoderByte Task 1 - maxString
More file actions
36 lines (31 loc) · 920 Bytes
/
Copy pathCoderByte Task 1 - maxString
File metadata and controls
36 lines (31 loc) · 920 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
36
import java.util.*;
import java.io.*;
class Main {
public static String ReplaceString(String str, String token){
StringBuilder sb = new StringBuilder();
for(int i=0; i<str.length(); i++){
char c = str.charAt(i);
if(token.contains(Character.toString(c)))
continue;
else sb.append(c);
}
return sb.toString();
}
public static String StringChallenge(String sen) {
// code goes here
String token = "s1otw2b";
String[] word = sen.split("\\W+");
String longest = word[0];
for(int i=0; i<word.length; i++){
if(word[i].length() > longest.length()){
longest = word[i];
}
}
return ReplaceString(longest, token);
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(StringChallenge(s.nextLine()));
}
}