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
What is an example of Big Data?
Y_Kistochka [10]

Answer:

providing real-time data feeds on millions of people with wearable devices

Explanation:

6 0
3 years ago
write a program in python to input 3 sides of a triangle. check if the triangle is equilateral, isosceles or scalene. use logica
hjlf
<h2>Type of Triangle - Python</h2>

In Geometry, a triangle is a three-sided polygon with three edges and three vertices. A triangle with vertices A, B, and C denoted ∆ABC.

<h3>Equilateral Triangle</h3>

A triangle is said to be an EQUILATERAL TRIANGLE if all the sides are equal in measure.

<h3>Isosceles Triangle</h3>

A triangle is said to be an ISOSCELES TRIANGLE if any two sides are equal in measure.

<h3>Scalene Triangle</h3>

A triangle is said to be a SCALENE TRIANGLE if none of the sides are equal in measure.

<h3>Here's our program:-</h3>

a = float(input("Enter the length of the first side of a triangle: "))

b = float(input("Enter the length of the

second side of a triangle: "))

c = float(input("Enter the length of the third side of a triangle: "))

if (a == b and b == c and c == a):

print("Equilateral Triangle.")

elif (a == b or b = c or c == a):

print("Isosceles Triangle.")

elif (a != b and b !=c and c != a):

print("Scalene Triangle.")

<h3>else:</h3>

print("Invalid Input.")

6 0
2 years ago
To create a public key signature, you would use the ______ key.
olya-2409 [2.1K]

Answer:

To create a public key signature, you would use the <u>_private_</u> key.

Explanation:

To create a public key signature, a  private key is essential to enable authorization.

A private key uses one key to make data unreadable by intruders and for the data to be accessed the same key would be needed to do so.

The login details and some important credentials to access user data contains both the user's public key data and private key data. Both private key and public key are two keys that work together to accomplish security goals.

The public key uses different keys to make data readable and unreadable.

The public key is important to verify authorization to access encrypted data by making sure the access authorization came from someone who has the private key. In other words, it's a system put in place to cross-check the holder of the private key by providing the public key of the encrypted data that needed to be accessed. Though, it depends on the key used to encrypt the data as data encrypted with a public key would require a private key for the data to be readable.

4 0
3 years ago
Accessing calendars, contact information, email, files and folders, instant messaging, presentations, and task lists over the in
Illusion [34]
The answer is Cloud Computing.  It access calendars, contact information, email, files and folders, instant messaging, presentations, and task lists over the internet. This means, if you have a device and an internet connection, you can have your "office" anywhere, anytime.
4 0
2 years ago
Read 2 more answers
Selling someone else's art, writing, music, or recording for your sole benefit is a copyright violation.
KATRIN_1 [288]
True urcifjwjcjkwjsjgv
8 0
3 years ago
Read 2 more answers
Other questions:
  • Raeball was a lovin doll. And she spoke her mind as she stood tall. She made you special and loved. You're missed by so many. An
    10·2 answers
  • Solar power plants trap the sun’s energy and convert it into electricity. What is a problem associated with this technology?
    11·1 answer
  • High-speed memory that reduces the frequency of access by the cpu to conventional memory is called
    12·1 answer
  • Create a program that prints out a list of all the divisors of a number stored in a variable. (If you don’t know what a divisor
    11·1 answer
  • Which statement best compares routers and hubs?
    9·1 answer
  • Jack lost all the data he saved on his desktop because of a power outage while working on a presentation. On which of these comp
    15·2 answers
  • Which of the following is the most abstract?
    13·2 answers
  • Mrs. Schlair has an annual salary of $96,402.<br> a. What would her semimonthly salary be?
    9·1 answer
  • What is the remainder obtained by dividing x 7 + x 5 + 1 by the generator polynomial x 3 + 1?
    9·1 answer
  • A(n) ____ describes the structure, content, and access controls of a physical data store or database.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!