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
disa [49]
3 years ago
7

Write a recursive method called repeat that accepts a string s and an integer n as parameters and that returns s concatenated to

gether n times. For example, repeat("hello", 3) returns "hellohellohello", and repeat("ok", 1) returns "ok", and repeat("bye", 0) returns "". String concatenation is an expensive operation, so for an added challenge try to solve this problem while performing fewer than n concatenations.
Computers and Technology
1 answer:
svp [43]3 years ago
6 0

Answer:

public static String repeat(String text, int repeatCount) {

   if(repeatCount < 0) {

       throw new IllegalArgumentException("repeat count should be either 0 or a positive value");

   }

   if(repeatCount == 0) {

       return "";

   } else {

       return text + repeat(text, repeatCount-1);

   }

}

Explanation:

Here repeatCount is an int value.

at first we will check if repeatCount is non negative number and if it is code will throw exception.

If the value is 0 then we will return ""

If the value is >0 then recursive function is called again untill the repeatCount value is 0.

You might be interested in
Write a while loop that continues to increment uservalue by 5 as long as uservalue is less than 0.
yan [13]

Using the knowledge in computational language in mathlab it is possible to write a code that while loop that continues to increment uservalue by 5 as long as uservalue is less than 0.

<h3>Writting the code:</h3>

<em>function </em><em>userValue </em><em>= IncreaseValue(userValue)</em>

<em>while(userValue<0)</em>

<em>userValue = </em><em>userValue</em><em>+5;</em>

<em>end</em>

<em>end</em>

<h3>How to run a code in MATLAB?</h3>

To run: If inside the Editor window: on the toolbar choose the Run icon; or in the Debug menu choose the Run option; or press F5. If the file is saved in memory, just type its name in the command window.

See more about mathlab at brainly.com/question/12975450

#SPJ1

7 0
1 year ago
What is food technology​
bonufazy [111]

Answer:

is the application of food science to the selection, preservation, processing, packaging, distribution, and use of safe food. Related fields include analytical chemistry, biotechnology, engineering, nutrition, quality control, and food safety management.

Explanation:

4 0
3 years ago
Louis is a civil engineer and wants to use a line on a floor plan that is indicative of the position from which a section is tak
frutty [35]

Answer:

A

Explanation:

horizontal line

8 0
3 years ago
Read 2 more answers
Which of the following is most accurate?
Sphinxa [80]
D. Because its not the only measurement which says in a. Its not B because waist measurement is also important. and its not C since D is the perfect method
4 0
3 years ago
How do you add text to a blank slide layout?
melisa1 [442]

The answer is B; Draw a text box and enter text

By default, we add text to a PowerPoint slide by typing it directly into a placeholder. However, you can use a text box to enter text into a blank slide or outside the placeholders. To add text on a blank slide click on the insert menu and select the Text box option. Click and hold down your mouse button while you drag the mouse. You will then clink inside the text box and starting typing.


6 0
3 years ago
Read 2 more answers
Other questions:
  • Select the proper ergonomic keyboarding techniques.
    15·2 answers
  • How does microchip work
    12·1 answer
  • print out the last even number from an array of integers, if there is no even number, then print out a sentence indicating so.
    5·1 answer
  • An instruction book or program that takes users through a prescribed series of steps to learn how to use a program is called (a)
    10·1 answer
  • Which of the following could be a constructor for the public class MyClass? a. public MyClass() b. public void MyClass() c. publ
    7·1 answer
  • Which protocol sends a request to view or download a website or file ​
    7·1 answer
  • A protester seeking to make a political point by leveraging technology tools, often through system infiltration, defacement, or
    8·1 answer
  • What are the steps to customize a slide show?
    10·2 answers
  • 2. How does the internet give us the ability to communicate?
    15·1 answer
  • What are the major benefits of preproduction?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!