Question: /** P2.12 Encodes a string by replacing azz Zetters i with ! and azz Zetters s with $. Use the replace method. Do this with

/** P2.12 Encodes a string by replacing azz Zetters "i" with "!" and azz Zetters "s" with "$". Use the replace method. Do this with variable town, assigning the result to variable townEncoding, and with the variable sentence, assigning the result to variable sentenceEncoding. */ public class ReplaceTester { public static void main(String[] args) { String town = "Mississauga" ; String townEncoding; String sentence = "This is a simple sentence." ; String sentenceEncoding ; //-----------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 "!" ; 1/2. now replace s to $ in string townEncoding ; 1/3. assign to sentenceEncoding the result of applying replace() on sentence to replace "i" with "?". 1/4. now replace s with $ in string sentenceEncoding. //--------- -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.")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
