Replace - { int index = phrase2.indexOf(" " +...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Replace { public static void main(String[] args) { System.out.print("Enter a phrase: "); String phrase = IO.readString(); System.out.print("Replace what: "); String word1 = IO.readString(); System.out.print("With what: "); String word2 = IO.readString(); S String phrase2 = " " + phrase.toLowerCase() + " "; phrase = " " + phrase + " "; p while (phrase2.indexOf(" " + word1.toLowerCase() + " ") >= 0 && phrase2.indexOf(" " + word1.toLowerCase() + " ") < phrase.length())
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { int index = phrase2.indexOf(" " + word1 + " "); String before = phrase.substring(0, index); String after = phrase.substring(index + word1.length() + 1,phrase.length()); phrase2 = before.toLowerCase() + " " + word2 + after.toLowerCase(); phrase = before + " " + word2 + after; } System.out.println(phrase.substring(1)); } }...
View Full Document

This note was uploaded on 11/03/2009 for the course CS 01-111 taught by Professor Pradiphari during the Fall '09 term at Rutgers.

Ask a homework question - tutors are online