Answer:
Written in Java
The complete program is as follows:
import java.util.Scanner;
public class RemoveString{
public static void main(String [] args){
String oldSeq, newSeq, segment;
Scanner input = new Scanner(System.in);
System.out.print("oldSeq: ");
oldSeq = input.next();
System.out.print("Segment: ");
segment = input.next();
newSeq=oldSeq.replaceFirst(segment, "");
System.out.print("newSeq: "+newSeq);
}
}
Step-by-step explanation:
This line declares necessary variables
String oldSeq, newSeq, segment;
Scanner input = new Scanner(System.in);
This line prompts user for oldSeq
System.out.print("oldSeq: ");
This line gets oldSeq
oldSeq = input.next();
This line prompts user for Segment
System.out.print("Segment: ");
This line gets segment
segment = input.next();
This line computes newSeq and it works perfectly for the given instances in the question
newSeq=oldSeq.replaceFirst(segment, "");
This line prints newSeq
System.out.print("newSeq: "+newSeq);