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
A(n) _________________________ is a character that word displays on the screen but is not visible on a printed document.
oksano4ka [1.4K]
Nonprint ...but im like 99 percent sure
6 0
3 years ago
Create the following matrix M: 1 7 13 19 25 ?-3 9 15 21 27 5 11 17 2329By writing one command and using the colon to address ran
zimovet [89]

Answer:

Matlab code is:

>> M=reshape(1:2:29, 3,5)

>> \%  (a)

>> Va=M(3,:)

>> \% (b)

>> Vb=M(:,4)

>> \% (c)

>> Vc=[M(2,:) M(:,3)']

Explanation:

>>\% \ Making\ the\ Matrix\ With\ required\ terms\ 1\ to\ 29\ with\ spaces\ of\ 5\ in\ three\ rows

>> M=reshape(1:2:29, 3,5)

M =

              1   7  13  19  25

              3  9  15  21  27

              5  11  17  23  29

>> \%  (a)

>>\%\ Slicing\ M\ \ from\ third\ row\ till\ end

>> Va=M(3,:)

Va =\\\ 5\ 11\ 17\ 23\ 29

>> \% (b)

>>\% \ Slicing\ the\4th\ column\ of\  M\ matrix\

>> Vb=M(:,4)

Vb =\\ 19\\ 21\\ 23\\

>> \% (c)

>>\% \ slicing\ the\ 2nd\ row\ and\ 3rd\ column\ of\ M\ Matrix\ and\ combining\ them\ to\ make\ a\ row\ matrix

>> Vc=[M(2,:) M(:,3)']

Vc =\\ 3\ 9\ 15\ 21\ 27\ 13\ 15\ 17

>>

The code is tested and is correct. If you put a semi colon ' ; ' at the end of every statement then your answer will be calculated but matlab doesn't show it until you ask i.e. typing the variable (Va, Vb, Vc )and press enter.

6 0
3 years ago
Where can elicitation techniques be used?
Nikitich [7]

Answer:

An elicitation technique is any of a number of data collection techniques used in anthropology, cognitive science, counseling, education, knowledge engineering, linguistics, management, philosophy, psychology, or other fields to gather knowledge or information from people.

Explanation:

3 0
2 years ago
Given that Jamie worked 50 hours (Hours = 50) last week and earns $10.00 an hour (Rate = 10), how much did Jamie earn last week,
quester [9]

Answer:

<em>Jamie earned (Total pay)  $500.</em>

<em></em>

Explanation:

We are given the following code:

<em>If (Rate >=10) OR (Hours <=40) Then </em>

<em>    TotalPay = Hours * Rate </em>

<em>Else </em>

<em>    TotalPay = (Hours * Rate)+(Hours–40)*Rate*1.5 </em>

<em>End If</em>

<em />

Let us understand the code line by line:

The first line contains an if statement with 2 conditions:

i.e. 1st condition:

The rate is greater than or equal to 10

2nd condition:

Number of hours are lesser than or equal to 40.

There is OR between the two condition i.e. the statement next to if() statement will get executed if any one of them becomes true and else part will not be executed.

The next statement is:

TotalPay = Hours * Rate

It calculates the pay if any of the two conditions written earlier becomes true.

Next statement is else statement:

It will get executed given that the above if() statement becomes false.

Now, we are given that Jamie worked 50 hours last week and earns $10.00 an hour:

i.e.

Hours = 50

Rate = 10

Now, let get to the code execution.

The first condition is true i.e. Rate >= 10 (because Rate is 10 here)

So, the following statement will be used to calculate the Total pay:

TotalPay = Hours * Rate

and else part will not be executed.

TotalPay = 50 * 10  =<em> $500  </em>

<em></em>

<em>Jamie earned (Total pay)  $500.</em>

3 0
3 years ago
Which of the following is NOT a way the media communicates unrealistic body images?
Leokris [45]

The media communicates unrealistic body image through various ways, which are mentioned in the available options for the question. It definitely digitally alters images that they use for their various publications, and it also provides forums to discuss actor and actresses, including their looks.

The media also often criticizes high-profile individual’s current body condition – whether they are too underweight or too overweight. Thus, the best answer for the question would be (D) promoting all body types.

6 0
3 years ago
Read 2 more answers
Other questions:
  • True or false. Embedding only part of a font is called presetting.
    14·1 answer
  • Copy the following code and run it. You should break it into the following 3 functions
    6·1 answer
  • Who can provide you with a new password when you have forgotten your old one?
    14·2 answers
  • ? Question
    6·2 answers
  • Which staff member takes a set of plans and supervises their construction?
    6·1 answer
  • Identify what a computer needs to
    14·1 answer
  • What is the code for forgot password on messenger​
    9·1 answer
  • I am stuck on these 2 questions. Can someone help me please?
    10·1 answer
  • The diagram shows the positions of the Sun, Earth, and Moon during each moon phase. When viewed from Earth, at what point does t
    15·1 answer
  • Why is technology bad for you
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!