1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
OlgaM077 [116]
3 years ago
13

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

ent 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.
Computers and Technology
1 answer:
nalin [4]3 years ago
5 0

Answer:

import java.util.*;

class Main

{

private String[] totalSandwiches(String string1,String string2)

{

int totalElements = string1.length()-1;

String ans[] = new String[totalElements];

for(int i=0;i<totalElements;i++)

{

String temp = "";

for(int j=0;j<=i;j++)

{

temp+=string1.charAt(j);

}

temp+=string2;

for(int j=i+1;j<string1.length();j++)

{

temp+=string1.charAt(j);

}

ans[i] = temp;

}

return ans;

}

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

Main obj = new Main();

String string1,string2;

System.out.print("Enter the 1st String: ");

string1 = sc.nextLine();

while(string1.length()<2)

{

System.out.print("The size of string 1 should be atleast 2 to make a sandwich. Enter the string again: ");

string1 = sc.nextLine();

}

System.out.print("Enter the 2nd String: ");

string2 = sc.nextLine();

while(string2.length()==0)

{

System.out.print("The size of string 2 should be atleast 1 to make a sandwich. Enter the string again: ");

string2 = sc.nextLine();

}

System.out.println("Following are the sandwiches: ");

String ans[] = obj.totalSandwiches(string1,string2);

for(int i=0;i<ans.length;i++)

{

System.out.println(ans[i]);

}

}

}

Explanation:

  • Run a while loop upto the total no. of elements and calculate number of elements from the string1 that should come before string2 .
  • Append the remaining characters of string1 are to temp.
  • The ans array stores the temp at ith index.
  • string1 characters are stored by the variable j.
  • Sandwich is not possible if string1 has less than 2 elements and possible if string2 has no elements.
  • Finally display the sandwich strings.
You might be interested in
Which of the following is not a use of a hash function
soldi70 [24.7K]

Answer:

the answer would be there

Explanation:

7 0
3 years ago
Designing a mouse to fit well in your hand would demonstrate ..?
mr Goodwill [35]

Answer:

Hi myself Shrushtee.

Explanation:

Your answer is

A) software engineering,

please mark me as brainleist

3 0
3 years ago
Read 2 more answers
Two types of business communications enhanced by desktop publishing are
Likurg_2 [28]
The correct option is D.
The two types of business communication that are enhanced by desktop publishing are internal and external communication. Internal communication refers to the information and ideas that are exchange within the organisation while external communication refers to information and ideas that are exchange between the organisation and the outside world.<span />
4 0
3 years ago
Read 2 more answers
The most accurate reading that you can take on an analog vom are when the meters pointer is at the?
marshall27 [118]
<span>The most accurate readings are near the right end of the scale, for two reasons. Any inaccuracy in your reading is a smaller part of the total voltage near full scale, and readings near the left end are likely to be off because of incorrect adjustment of the zero adjust screw. If "extreme right" means past the end of the numbers, you may be off there if the needle hits the stop. On meters with a mirror behind the needle, move to where the needle is in front of its reflection for the best reading.</span>
4 0
3 years ago
Using the phase plane program described in the introduction, plot the phase plane for the Lotka-Volterra model Here represents t
dezoksy [38]

Answer:

Check the explanation

Explanation:

Kindly check the attached image.

The attached image below describes the inner equilibrium point is a stable node, here it's a center. These are periodic solutions. Populations of the mice and owls are periodic. It describes: when the mice population is lower, the owl population decreases; again the owl is lower so mice got a chance to grow its population; now as sufficient food(mice) is there, the owl population increases; as predator population increases, the prey population decreases;  and this continues as a cycle forever.

So, yes, the model gives a realistic behavior.

4 0
4 years ago
Other questions:
  • One in five teens have been tricked by someone online:
    14·2 answers
  • A restaurant has a case type that allows customer to book the dining room for events. Customers provide basic information includ
    7·1 answer
  • Sending a busy manager a long email represents a problem in which area of the communication process
    7·1 answer
  • Define function multiply(), and within the function: Get user input() of two strings made of whole numbers Cast the input to int
    11·1 answer
  • Anyone know the name of this font? and what site i can find it on so i can type it????
    8·1 answer
  • Robert is leading a project online that includes students from different cultures. Two of the students spend most of the time li
    7·1 answer
  • A histogram titled Greeting card sales has date on the x-axis and cards (millions) on the y-axis. January is 1 card, February: 1
    12·2 answers
  • What is the purpose of a report?
    6·2 answers
  • PLEASE HELP!!<br> Would you ever try and get famous off of social media? Why or why not?
    6·2 answers
  • When scriptwriters are writing scripts, why do they have to write them in accordance with industry standards?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!