Encode a string by replacing all letters i with ! and all letters s with $. Use
Question:
Encode a string by replacing all letters "i" with "!" and all letters "s" with "$". Use the replace method. Do this with the variable town, assigning the result to variable own encoding, and with the variable sentence, assigning the result to variable sentence encoding.
*/
public class ReplaceTester
{
public static void main(String[] args)
{
String town = "Mississauga" ;
String townEncoding ;
String sentence = "This is a simple sentence." ;
String sentence encoding ;
//-----------Start below here. To do: approximate lines of code = 4
// 1. Assign to townEncoding the result of applying the replace method to town to replace "i" with "!" ;
//2. now replace s to $ in string townEncoding ;
//3. assign to sentence encoding the result of applying to replace() on sentence to replace "i" with "!".
//4. now replace s with $ in string sentence encoding.
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
System.out.println("Encoding of town:" + townEncoding) ;
System.out.println("Encoding of sentence:" + sentenceEncoding) ;
System.out.println("Expect:") ;
System.out.println("Encoding of town: M!$$!$$auga" ) ;
System.out.println("Encoding of sentence: Th!$ !$ a $!mple $entence.") ;
}
}
Discrete Mathematics and Its Applications
ISBN: 978-0073383095
7th edition
Authors: Kenneth H. Rosen