Like a lion

Report a typo

Gabe N. works at a zoo and has a special keyboard that replaces all occurrences of "lion" with "guinea pig". He decided to write a Java program that would simulate this keyboard and replace all occurrences of the "lion" substring in a user-entered string with the "guinea pig" substring. Help Gabe N. write this program using regular expressions and Matcher. Implement the replace method that takes a string, replaces all the words "lion" with "guinea pig", and returns the result.

Sample input 1:

like a lion

Sample output 1:

like a guinea pig

Sample input 2:

In Africa, a lion runs across the savannah in search of prey.

Sample output 2:

In Africa, a guinea pig runs across the savannah in search of prey.

Sample Input 1:

like a lion

Sample Output 1:

like a guinea pig
Write a program in Java 17
import java.util.Scanner;

public class Main {
private static String replace(String input) {
// write your code here
return null;
}

// Don't change the code below
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
System.out.println(replace(line));
}
}
___

Create a free account to access the full topic