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
Becca is working on a program that will store data. The program will need quick access to data and data persistence is not impor
borishaifa [10]

Based on the information given the data should be stored in flash memory.

<h3>What is flash memory:</h3>

Flash memory is a memory storage space that is used to store data or information on a computer.

Flash memory is vital as it help to retain information or data that are stored on a computer after power is removed which inturn means that store data can be retrieve when needed.

Example of flash memory are:

  • CompactFlash  
  • Memory Stick
  • BIOS chip etc

Inconclusion the data should be stored in flash memory.

Learn more about flash memory here:brainly.com/question/6835146

7 0
2 years ago
Please someone help!!!!
Montano1993 [528]

Answer:

do what the directions say and you should be able to figure out the answer if not contact me through brainly

Explanation:

3 0
3 years ago
Is anyone else excited for sephiroth (I think I spelt it wrong) in smash. And if you arn't are you excited for christmas
Fed [463]

Answer: idek what that is but okay ;v;

7 0
3 years ago
Which statement best describes the Tell Me feature in PowerPoint 2016?
Bumek [7]

A statement best describes the Tell Me feature in PowerPoint 2016 is that: D. it opens a search field that can be used to look up old versions of presentations.

<h3>What is PowerPoint 2016?</h3>

PowerPoint 2016 refers to a software application that was designed and developed by Microsoft Inc., so as to avail its end users the ability to create various slides which can be used during a presentation.

In PowerPoint 2016, the Tell Me feature is a tool which opens a search field that can be used by end users to look up or search old versions of presentations.

Read more on PowerPoint here: brainly.com/question/26404012

#SPJ1

6 0
1 year ago
The system tray contains _____.
xeze [42]

Answer:

the system tray is located in the Windows Taskbar (usually at the bottom next to the clock) and contains miniature icons for easy access to system functions such as fax, printer, modem, volume, and more. Double click or right click on an icon to view and access the details and controls.

Explanation: in window 95

7 0
3 years ago
Read 2 more answers
Other questions:
  • Select the correct answer.
    6·1 answer
  • 1)Ce procent de grasimi putem găsi in lapte ?
    10·1 answer
  • A style manual can be described as
    11·2 answers
  • Please refer to the MIPS solution in the question above. How many total instructions are executed during the running of this cod
    10·2 answers
  • Internet is for everyone but it wont be if its users cannot protect their privacy and the confidentiality of transactions conduc
    6·1 answer
  • Which question can most help a writer revise an argumentative essay?
    9·2 answers
  • What is a good rule of thumb for how much white space you should have in a flyer or poster
    7·2 answers
  • There is an interface I that has abstract class AC as its subclass. Class C inherits AC. We know that C delegates to an object o
    12·1 answer
  • 4. Give four reasons why a laptop computer is more expensive than a desktop computer of the
    10·1 answer
  • A __________ is a thorough examination of each aspect of a network to determine how it may be compromised.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!