Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Reopened by Boann java Users with the java badge or a synonym can single-handedly close questions as duplicates and reopen them as needed.
added 16 characters in body
Source Link

I am trying to make a program that censors the word "dang" with a "#!". My main method passes in a String sentence.

public static String deleteDang(String sentence)
 /* pre: receives the sentence to be censored
 post: returns the censored sentence*/
 {
 while(((sentence.toLowerCase()).contains("dang")))
 {
 sentence = (sentence.toLowerCase()).replace("dang", "#!");
 }
 return sentence;
 }

I want it to be work so that I can enter something such as "DANG ApplE" and get the output "!# ApplE". When I attempt to run this, it outputs "!# apple" if I input "dang apple", but when I put in "DANG Apple", I have an infinite output of "DANG Apple". What am I doing wrong?

If possible, I would like to this without the use of .replaceAll

I am trying to make a program that censors the word "dang" with a "#!". My main method passes in a String sentence.

public static String deleteDang(String sentence)
 /* pre: receives the sentence to be censored
 post: returns the censored sentence*/
 {
 while(((sentence.toLowerCase()).contains("dang")))
 {
 sentence = sentence.replace("dang", "#!");
 }
 return sentence;
 }

I want it to be work so that I can enter something such as "DANG ApplE" and get the output "!# ApplE". When I attempt to run this, it outputs "!# apple" if I input "dang apple", but when I put in "DANG Apple", I have an infinite output of "DANG Apple". What am I doing wrong?

If possible, I would like to this without the use of .replaceAll

I am trying to make a program that censors the word "dang" with a "#!". My main method passes in a String sentence.

public static String deleteDang(String sentence)
 /* pre: receives the sentence to be censored
 post: returns the censored sentence*/
 {
 while(((sentence.toLowerCase()).contains("dang")))
 {
 sentence = (sentence.toLowerCase()).replace("dang", "#!");
 }
 return sentence;
 }

I want it to be work so that I can enter something such as "DANG ApplE" and get the output "!# ApplE". When I attempt to run this, it outputs "!# apple" if I input "dang apple", but when I put in "DANG Apple", I have an infinite output of "DANG Apple". What am I doing wrong?

If possible, I would like to this without the use of .replaceAll

added 68 characters in body
Source Link

I am trying to make a program that censors the word "dang" with a "#!". My main method passes in a String sentence.

public static String deleteDang(String sentence)
 /* pre: receives the sentence to be censored
 post: returns the censored sentence*/
 {
 while(((sentence.toLowerCase()).contains("dang")))
 {
 sentence = sentence.replace("dang", "#!");
 }
 return sentence;
 }

I want it to be work so that I can enter something such as "DANG ApplE" and get the output "!# ApplE". When I attempt to run this, it outputs "!# apple" if I input "dang apple", but when I put in "DANG Apple", I have an infinite output of "DANG Apple". What am I doing wrong?

If possible, I would like to this without the use of .replaceAll

I am trying to make a program that censors the word "dang" with a "#!". My main method passes in a String sentence.

public static String deleteDang(String sentence)
 /* pre: receives the sentence to be censored
 post: returns the censored sentence*/
 {
 while(((sentence.toLowerCase()).contains("dang")))
 {
 sentence = sentence.replace("dang", "#!");
 }
 return sentence;
 }

I want it to be work so that I can enter something such as "DANG ApplE" and get the output "!# ApplE". When I attempt to run this, it outputs "!# apple" if I input "dang apple", but when I put in "DANG Apple", I have an infinite output of "DANG Apple". What am I doing wrong?

I am trying to make a program that censors the word "dang" with a "#!". My main method passes in a String sentence.

public static String deleteDang(String sentence)
 /* pre: receives the sentence to be censored
 post: returns the censored sentence*/
 {
 while(((sentence.toLowerCase()).contains("dang")))
 {
 sentence = sentence.replace("dang", "#!");
 }
 return sentence;
 }

I want it to be work so that I can enter something such as "DANG ApplE" and get the output "!# ApplE". When I attempt to run this, it outputs "!# apple" if I input "dang apple", but when I put in "DANG Apple", I have an infinite output of "DANG Apple". What am I doing wrong?

If possible, I would like to this without the use of .replaceAll

Post Closed as "Duplicate" by Community Bot
Source Link

Cannot replace with Java replace method

I am trying to make a program that censors the word "dang" with a "#!". My main method passes in a String sentence.

public static String deleteDang(String sentence)
 /* pre: receives the sentence to be censored
 post: returns the censored sentence*/
 {
 while(((sentence.toLowerCase()).contains("dang")))
 {
 sentence = sentence.replace("dang", "#!");
 }
 return sentence;
 }

I want it to be work so that I can enter something such as "DANG ApplE" and get the output "!# ApplE". When I attempt to run this, it outputs "!# apple" if I input "dang apple", but when I put in "DANG Apple", I have an infinite output of "DANG Apple". What am I doing wrong?

lang-java

AltStyle によって変換されたページ (->オリジナル) /