Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the WordSandwich method allSandwiches . This method creates and returns a new array of String objects as follows. Each element of the array will

Write the WordSandwich method allSandwiches. This method creates and returns a new array of String objects as follows.

Each element of the array will be a sandwich of str1 and str2: that is the characters of str2 are inserted into str1. The first String in the array consists of 1 letter of str1 followed by str2, followed by the rest of the letters of str1. For each subsequent String in the array the position in str1 where str2 starts is shifted by 1 until the final string in the array which consists of all but 1 letter of str1 followed by str2, followed by the final remaining letter of str1. For example, the call allSandwiches(bread, ham) will return the following array.

{bhamread, brhamead, brehamad, breahamd}

In writing allSandwiches you may call makeSandwich. Assume that makeSandwich works as specific regardless of what you wrote in part (a).

Complete method allSandwiches below.

 /** @param str1 a string * @param str2 another string * Precondition: str1.length() > 1 * @return An array of String objects created by inserting str2 into sequentially * different positions in str1. */ private String[] allSandwiches(String str1, String str2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

What are the determinants of cash cycle ? Explain

Answered: 1 week ago