Java: Programming - World Peace
Change all occurences of "war" to "peace"
The US Department of Defense used to be called the War Department. I wouldn't be surprised if the public relations gurus eventually change it to Department of Peace.
In this same spirit you should write a program to produce world peace
by scanning the input for the word "war" and replace it with "peace".
The Java function replace may not be used for this --
you have to write it yourself.
Iterative development hints
- Write a program to just input a string.
- Use
indexOfto tell whether it had the word "war" in it or not. - Be sure your code works both when "war" occurs and when it doesn't.
- Use
indexOfandsubstringto extract the part before "war" and after "war" and build a new string where "war" is replaced by "peace". - Write a loop to replace ALL occurences of "war" with "peace".
Extra credit
Upper- and lowercase are problems. Add code to deal with case problems.















