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]
2 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]2 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
Type the correct answer in the box. Spell all words correctly.
allsm [11]

Answer:

Ground Antennas

Explanation:

I got it right on my test

5 0
2 years ago
Explain the importance of mobile computing in communication​
ludmilkaskok [199]
<h3><em><u>Importance of Mobile computing in communication</u></em></h3>

*It’s portable and easy-to-use.

*It helps for different communication and information exchange.

*It saves user’s time and effort.

*It provides quick services like online business, e-mail, e-fax, etc.

*It increases the social interaction by sharing location services and GPS system.

7 0
2 years ago
Read 2 more answers
A time stamp indicates the date and time that a measurement was taken. A data scientist has a list containing 10,000 time stamps
snow_tiger [21]

Binary search involves searching a sorted list

The number of values that will be examined is 15

<h3>How to determine the number of examined values</h3>

The equation that calculates the number of values that will be examined is:

2^{n -1} = N

Where n represents the number of values to examine and N represents the number of time stamps

So, we have:

2^{n -1} = 10000

Take the log of both sides

\log(2^{n -1}) = \log(10000)

Apply the laws of logarithm

[n - 1]\log(2) = 4

Divide both sides y log(2)

n - 1 = 13.2

The next integer greater than 13.2 is 14.

So, we have:

n - 1 = 14

Add 1 to both sides

n = 15

Hence, the number of values that will be examined is 15

Read more about binary search at:

brainly.com/question/20411780

3 0
2 years ago
The people on this platform are unbelievably nice. its almost rare to see this type of kindness online these days. Just wanted t
baherus [9]

Answer:

thanks

Explanation:

5 0
3 years ago
Here's a thought: Why does your Brainly ranking keep going down?
kirill115 [55]
Yeah youre right because thats how the website works??
5 0
2 years ago
Read 2 more answers
Other questions:
  • PLS HELP ASAP! WILL GIVE BRAINLIEST!
    14·1 answer
  • When the packet leaves the router, which source and destination ip addresses will be contained in the packet?
    9·1 answer
  • Which of these can be considered data?<br> A:facts<br> B:information<br> C:belief<br> D:all of these
    9·1 answer
  • A(n) ____ is the computer counterpart to an ordinary paper file you might keep in a file cabinet or an accounting ledger.a. data
    6·1 answer
  • Which tab provides commands for the most commonly used elements in Word software?
    15·1 answer
  • Settings to control the amount of notifications is a
    10·2 answers
  • Alexi is writing a program which prompts users to enter their age. Which function should she use?
    6·2 answers
  • What is a geam in the ggplot2 system?
    5·1 answer
  • Select the correct answer from each drop-down menu. A company is recruiting for a web designer. What kind of candidate should th
    14·2 answers
  • A word or phrase to help identify a file when you do not know the file name during the file expiration search
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!