153k views
2 votes
Write a program HelloPrinter that switches the letters "e" and "o" in a string. Use the replace method repeatedly. Demonstrate that the string " Hello", world!" turns into " Holle, werld!"

1 Answer

7 votes

Answer:

public class Printing

{

public static void main(String[] args)

{

String letters = "Hello, World!";

String letters2 = letters.replace("o" , "e");

String letters3 = letters.replace("e" , "o");

System.out.println(letters3);

}

}

Step-by-step explanation:

We start by defining a class called Printing. We take a string variable to store "Hello, World!";. Then we use replace method 2 times to switch the letters "e" and "o". Finally we print the last String variable where the latest replacement is stored.

User Andrea Olivato
by
6.7k points