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
iogann1982 [59]
3 years ago
10

Write a static method called bothStart that allows the user to input two Strings and returns the String that is the longest subs

tring s such that both inputs start with s.
For example,


bothStart( "radar dish", "radical food" ) returns "rad"


bothStart( "radar disk", "disk radar" ) returns ""


bothStart( "radar installation", "" ) returns ""


bothStart( "Mendacious", "Mendicant" ) returns "Mend"


bothStart( "FRANKLY", "frank" ) returns ""
Computers and Technology
1 answer:
marishachu [46]3 years ago
5 0

Answer:

  1.    public static String bothStart(String text1, String text2){
  2.        String s = "";
  3.        if(text1.length() > text2.length()) {
  4.            for (int i = 0; i < text2.length(); i++) {
  5.                if (text1.charAt(i) == text2.charAt(i)) {
  6.                    s += text1.charAt(i);
  7.                }else{
  8.                    break;
  9.                }
  10.            }
  11.            return s;
  12.        }else{
  13.            for (int i = 0; i < text1.length(); i++) {
  14.                if (text1.charAt(i) == text2.charAt(i)) {
  15.                    s += text1.charAt(i);
  16.                }else{
  17.                    break;
  18.                }
  19.            }
  20.            return s;
  21.        }
  22.    }

Explanation:

Let's start with creating a static method <em>bothStart()</em> with two String type parameters, <em>text1 </em>&<em> text2</em> (Line 1).  

<em />

Create a String type variable, <em>s,</em> which will hold the value of the longest substring that both inputs start with the same character (Line 2).

There are two possible situation here: either <em>text1 </em>longer than<em> text2 </em>or vice versa. Hence, we need to create if-else statements to handle these two position conditions (Line 4 & Line 13).

If the length of<em> text1</em> is longer than <em>text2</em>, the for-loop should only traverse both of strings up to the length of the <em>text2 </em>(Line 5). Within the for-loop, we can use<em> charAt()</em> method to extract individual character from the<em> text1</em> & <em>text2 </em>and compare with each other (Line 15). If they are matched, the character should be joined with the string s (Line 16). If not, break the loop.

The program logic from (Line 14 - 20) is similar to the code segment above (Line 4 -12) except for-loop traverse up to the length of <em>text1 .</em>

<em />

At the end, return the s as output (Line 21).

You might be interested in
For a project called "The Sheep Market", Aaron Koblin collected drawings of sheep from strangers on the Internet. He posted the
Furkat [3]

Answer:

Aaron could expect a diversity in the style of the sheep drawings.

Explanation:

Crowdsourcing is a simply a sourcing model in which an individual or organizations get goods and services, ideas and finances, from a large, relatively open and often rapidly growing group of internet users.

It makes it easier for participants to achieve a cumulative result through working differently on the same project. That is to say, it provides work between participants to achieve a cumulative result.

Its benefits is that, Crowdsourcing allows businesses to perform tasks more quickly than when a single employee is working alone. Again, Breaking up a project into a collection of smaller pieces and providing these pieces to a larger group of workers hastens the completion of projects. Overall, crowdsourcing presents a more efficient way to do work.

From the Question, Aaron was able to get different pictures of sheep in their numbers also because he used crowsourcing on amazon.

He got a variety of pictures and so many in such a short time for his project "The Sheep Market".

6 0
3 years ago
In QBasic, create a number guessing challenge. Your program should generate a random number from 1-
Sergio039 [100]

Answer:

yes

Explanation:

6 0
3 years ago
Decimal numbers are based on __________.
Shtirlitz [24]
Decimals are based on the preceding powers of 10. Thus, as we move from left to right, the place value of digits gets divided by 10, meaning the decimal place value determines the tenths, hundredths and thousandths. A tenth means one tenth or 1/10. In decimal form, it is 0.1.
6 0
3 years ago
Suppose we wanted to make change for purchases and wanted to use the least number of coins possible. Here is a greedy algorithm:
love history [14]

Answer:

Explanation:

The following code is a Python function that takes in the amount of change. Then it uses division and the modulo operator to calculate the number of coins that make up the changes, using the greatest coin values first.

import math

def amountOfCoins(change):

   print("Change: " + str(change))

   quarters = math.floor(change / 0.25)

   change = change % 0.25

   dimes = math.floor(change / 0.20)

   change = change % 0.20

   pennies = math.floor(change / 0.01)

   print("Quarters: " + str(quarters) + "\nDimes: " + str(dimes) + "\nPennies: " + str(pennies))

5 0
3 years ago
How do you adjust the shear of a shape?
Aloiza [94]
The answer is D. Appearance panel
7 0
3 years ago
Read 2 more answers
Other questions:
  • Which presentation software element can you use to create a model diagram with two concentric circles inside a triangle?
    10·2 answers
  • What is the function of the keyboard shortcut Ctrl+Shift+E in a word processor
    5·2 answers
  • Impact of computer on education
    6·2 answers
  • Which term is used to describe the science of examining raw data, removing excess noise from the dataset, and organizing the dat
    15·1 answer
  • The standing toe touch is most likely to result in
    15·1 answer
  • When mapping a drive, you can type in the path to the shared folder on the host computer. what is the syntax for the path?
    7·1 answer
  • You want to establish the validity of a test designed for computer technicians using a predictive criterion-related validation s
    9·1 answer
  • When a chart is selected, numerous customization options can be found on which Chart Tools tabs?
    11·2 answers
  • You are now going to prepare some reports for the company. Measurements are in metres and volume
    7·1 answer
  • Multiple choice:
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!