-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoderByte Task 1
More file actions
39 lines (33 loc) · 954 Bytes
/
CoderByte Task 1
File metadata and controls
39 lines (33 loc) · 954 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
37
38
39
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))){
sb.append("--" + c + "--");
}
else
sb.append(c);
}
return sb.toString();
}
public static String StringChallenge(String str) {
// code goes here
String token = "zqotaem487b";
String[] words = str.split("\\W+");
String longest = words[0];
for(int i=0; i<words.length; i++){
if(words[i].length() > longest.length()){
longest = words[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()));
}
}