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
A software company is weighing whether to release a new version of its software as scheduled. The company can go ahead and relea
Kisachek [45]

Answer:

B) vaporware.

Explanation:

Vaporware is a software or hardware product that is not yet released in the market but has already advertised. This can be the product is probably still under development or it is still in its idea form and not developed at all. Vaporware is a term used in the computer products industry. Products that were announced but missed the released date by a big amount of time can also be called vaporware.

8 0
3 years ago
Which of the following is considered a benefit when using slab allocator?
tatyana61 [14]

Answer:

Option(d) is the correct answer to the given question

Explanation:

The main advantage of slab allocator is that There is no memory is lost because of the fragmentation this is due to some driver data framework has a cache memory that is connected to it.

  • In the slab allocator the resources are repeatedly assigned or free to handle them. It is a type of memory management scheme that is used for distributing resources to the memory.
  • All the other options are not considered as advantages of Slab allocator that's why they are an incorrect options.
7 0
3 years ago
What is the difference between Windows 7 and Windows 10?
Tanzania [10]
Windows 10 is new and windows 7 is old
6 0
3 years ago
Select the correct answer.
Shtirlitz [24]

Answer:

The right answer is text. we just need to just mention the date inside the text, and also mention the cell number, where you want that to be printed. The formula is Text(B1, "MM-DD-YY").

The other mentioned are a detailed information, and contains a mixed blend of information. The table, chart, flowchart and the shapes contains different data type. However, text is a data type, and date can be converted into text date type through the above formula. Hence, we are converting the date data type to text data type.

Explanation:

The answer is self explanatory.

6 0
3 years ago
An administrator is having some trouble with a disk partition and needs to do maintenance on this partition but their user's hom
Anvisha [2.4K]

Answer:

Option B.

Explanation:

init 1 command is used to fulfill the requirement mentioned above.

4 0
3 years ago
Other questions:
  • The initial step of the five-step problem-solving model is to: A. Explore alternatives B. Clarify values. C. Develop an approach
    9·1 answer
  • The _____ stage of information technology planning outlines business processes that are central to achieving strategic goals and
    10·1 answer
  • ________ computers are specially designed computer chips that reside inside other devices such as your car or the electronic the
    9·1 answer
  • What are three responsibilities of an operating system? please answer quick!!!
    9·1 answer
  • You need to provide connectivity between two buildings without running any cables. You decided to use two 802.11ac APs to provid
    14·1 answer
  • You create a new three-way mirror storage space. You format the storage space by using ReFS. Which two features can you use on t
    13·1 answer
  • You want to receive alerts if unusual activity is detected relating to the Web servers deployed in your perimeter network. What
    7·1 answer
  • 1.printer is an example of......... device.<br><br>​
    11·2 answers
  • 8. Why is it important not to download pictures to your school or workplace network if you do not plan to use them?
    10·1 answer
  • What is difference between computer and smartphone
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!