owly
Banned
- Nov 26, 2020
- 179
Java:
public class Grammer {
public String swapWords(String sentence, String w1, String w2) {
if (sentence.isEmpty()) {
return "";
}
if (sentence.contains(w1)) {
return sentence.replace(w1, w2);
} else {
if (sentence.contains(w2)) {
return sentence.replace(w2, w1);
}
}
return "";
}
}
System.out.println(grammer.toggleWords("brush my teeth", "my", "your"));
System.out.println(grammer.toggleWords("brush your teeth", "my", "your")); :
brush your teeth
brush my teeth
yeah she has a skill for that. and if I say thank you shortly after, waifubot will keep the reminder alive for tomorrow at the same time.