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
How is cropping different from scaling?​
Keith_Richards [23]

Answer:

Scaling changes the size of the whole image by resampling it(duplicating the pixels). in cropping you only get a part of the original image/ remove the outer area of it .

Explanation:

8 0
3 years ago
Select all that apply. Two physical things you can do to demonstrate you are paying attention to a speaker are _____ and _____.
omeli [17]
B and d ............
7 0
3 years ago
Read 2 more answers
Use the Wrap Text icon to _____. modify which graphic appears in the front of layered images modify the picture effects change t
sergey [27]

I believe it's change the way text is wrapped around an object.

3 0
3 years ago
Read 2 more answers
The ampacity of a No. 12 aluminum wire with RHW insulation installed in a raceway that has 19 other wires is
GREYUIT [131]
<span>i believe the answer is C</span>
7 0
3 years ago
Part of implementing Ken 7 Windows Limited new enterprise resource planning (ERP) software is ensuring all workstations and serv
spayn [35]

Answer:

Explanation:

1) The Functions a software application provide to keep a web browser secured includes:

a) The web browser should always be updated, you can keep it on "automatic update" option enable on your browser settings so that it will be automatically updated whenever the browser gets an update.

b) Always keep the third party cookies disabled because of the many unauthorized and phishing sites over the internet. This leaves the browser unsafe and cause higher security risk so block all the third party sites and cookies from the browser.

2) The Functions a software application prohibit to keep a web browser secured includes:

a) Do not store passwords on your web browser, deny the "store password" option on your browser settings. This is very important Even if you store passwords on your web browser do set a very strong master password to access all the stored passwords.

b) Don't ever click on unwanted and unknown hyperlinks. There will be many unsolicited attachments, files, etc over the internet please do not open or download it unnecessarily.

3) The functions a software application should provide to keep a web server secured includes:

a) Always using an application scanner. Whenever you install or download any new applications, scan the application before accessing it or opening it.

b) Install all the security patches to keep off hackers as they are many on the internet.

4) The Functions a software application should prohibit to keep a web server secured includes:

1) Uninstall an application that has not been used for long time, because they are actually of no use.

b) There may be scripts, files, setups, codes stored on the web server unknowingly so do check it and delete all the sample scripts, files and codes from the web server.

3 0
3 years ago
Other questions:
  • Plz answer me will mark as brainliest ​
    7·2 answers
  • DLucy is planning to launch her podcast on career guidance for college students and has already recorded a few videos for market
    10·1 answer
  • The class attribute a. can be applied to only one element in an HTML document b. determines the copy that will be displayed when
    5·1 answer
  • Write the definition of a function half which recieves a variable containing an integer as a parameter, and returns another vari
    15·1 answer
  • ​open-source software is​ ________.
    11·1 answer
  • ____________________________ and _________________________ are 2 negative impacts of the internet on businesses.
    8·1 answer
  • Helllllllllppppppppppp
    9·1 answer
  • The central point of Christian belief is that God, the Father, entered into human history as the
    15·1 answer
  • 3. Rajat wants to assign green colour to a paragraph. Write the code that will help him in completing the task
    9·1 answer
  • In Python, while loops will repeat during the time the test condition is true.
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!