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
which of the following sentences uses active voice?(answers to choose from are in the photo)-this is in my computer applications
andrezito [222]
Last week, Nate and I counted all the inventory. answer :A
6 0
3 years ago
Read 2 more answers
How is hardware different from sofware?
ExtremeBDS [4]

Answer:

Computer hardware is any physical device used in or with your machine, whereas software is a collection of code installed onto your computer's hard drive. For example, the computer monitor you are using to read this text and the mouse you are using to navigate this web page are computer hardware.

All software utilizes at least one hardware device to operate. For example, a video game, which is software, uses the computer processor (CPU), memory (RAM), hard drive, and video card to run. Word processing software uses the computer processor, memory, and hard drive to create and save documents.

6 0
3 years ago
Why might you use a navigation form instead of tab pages? The navigation form allows for several levels and sublevels to be coll
boyakko [2]

Answer:

Access includes a Navigation Control that makes it easy to switch between various forms and reports in your database. A navigation form is simply a form that contains a Navigation Control. Navigation forms are a great addition to any desktop database.

Explanation:

yes

3 0
3 years ago
Read 2 more answers
You are the IT security administrator for a small corporate network. You would like to use Group Policy to enforce settings for
LuckyWell [14K]

Answer/Explanation:

To Complete this lab, do the following:

1. From Server Manager, select Tools > Group Policy Management.

2. Expand Forest: CorpNet.com > Domains > CorpNet.com.

3. Right-click the OU where the policy will be linked and select Create a GPO in this domain, and link it here.

4. In the Name field, enter the GPO name; then click OK.

5. Link the GPO to additional OUs as follows:

a. Right-click the next OU and select Link an Existing GPO to link the GPO to another OU.

b. Under Group Policy objects, select Workstation Settings from the list; then click OK.

c. Repeat step 5 to link additional OUs.

6. Import a security policy template as follows:

a. Expand Group Policy Objects.

b. Right-click Workstation Settings and select Edit.

c. Under Computer Configuration, expand Policies > Windows Settings.

d. Right-click Security Settings and select Import Policy.

e. Browse to the C:\Templates.

f. Select ws_sec.inf; then click Open.

Cheers

3 0
3 years ago
Heather writes an essay for language arts and receives a poor grade. To figure out why she gets a poor grade, Heather looks at t
Kazeer [188]

Answer:

Glows and grows strat

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • Randy is concerned about his company’s data security on the Internet. Because cellular signals are not encrypted, he is concerne
    6·1 answer
  • A computer professional who has access to sensitive information shares this information with a third party. Which professional c
    9·2 answers
  • When using a target drive that is fat32 formatted, what is the maximum size limitation for split files?â?
    12·1 answer
  • Rapid development programming languages eliminate the possibility of having bugs in code. True or False
    8·1 answer
  • The region which satisfies all of the constraints in graphical linear programming is called the:
    8·1 answer
  • List the steps in setting up an online banking account
    12·2 answers
  • In Microsoft word when you highlight existing text you want to replace , you're in?
    15·1 answer
  • Assume you need to declare a type parameter that can represent any type that implements the interface Comparable. Which type par
    15·1 answer
  • 2.
    11·1 answer
  • What is the chip that allows the screen to work
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!