If oldSeq is "1100000111" and segment is "11", then "00000111" should be stored in newSeq. If oldSeq is "0000011" and segment is "11", then "00000" should be stored in newSeq. If oldSeq is "1100000111" and segment is "00", then "11000111" should be stored in newSeq. Write the code segment below. Your code segment should meet all specifications and conform to the examples.

Respuesta :

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);

}

}

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);

ACCESS MORE
EDU ACCESS
Universidad de Mexico