1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
public class NotReplace {
public static String notReplace(String sentence)
{
String wordSearched = "is";
if(sentence.contains(wordSearched))
sentence=sentence.replace(wordSearched, " is not ");
return sentence;
}
public static void main(String[]args)
{
String s="This is right.";
String s2="is-is";
String s3="is test";
String sentence = notReplace(s);
System.out.println(sentence);
String sentence2 = notReplace(s2);
System.out.println(sentence2);
String sentence3 = notReplace(s3);
System.out.println(sentence3);
}
} |
Partager