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
Which of the following websites is least biased
labwork [276]
I think it's D because it's made out of facts. The other ones are more likely to include bias.
8 0
4 years ago
An effective problem statement ensures that
swat32
The software design effectively addresses the issues
6 0
3 years ago
I need help now I really do what is the answer thank you
Svetradugi [14.3K]
The answer is c
just replace the y with the y value and the x with the x value
4 0
3 years ago
Who go to Tennessee Connection Academy And If yall Do plz comment down below.
zalisa [80]

Answer:

it a or d

Explanation:

7 0
3 years ago
Given two input integers for an arrowhead and arrow body, print a right-facing arrow.
Zanzabum

Answer:

I don't know the language this is but here is something that will work for all lang

int num0 = 0;

int num1 = 0;

basically just print the ints in the right dimension

Explanation:

Sorry if I am wrong

I don't know much about this someone else's answer might be better than mine

3 0
3 years ago
Other questions:
  • True or False. It is required to restart the client computer after the DLP agent has been installed.
    9·2 answers
  • When creating a professional presentation, how many typefaces are recommended at the most?
    5·1 answer
  • A customer has a web server for a small business. The business uses both wired and wireless networking. A Linksys WRT300N wirele
    13·1 answer
  • Answer the following questions which are based on the study "Patients' Engagement with Sweet Talk." Submit your answers to the e
    9·1 answer
  • If you are unsure about what is or isn’t appropriate to wear to a new job, what is the best thing to do?
    13·2 answers
  • What are the first two lines of defense a company should take when addressing security risks?
    10·1 answer
  • A package that includes hardware, software, and support from a single vendor is called a(n ____ package.
    6·1 answer
  • A firm can survive and succeed in the long run if it successfully develops strategies to confront the _______________ that shape
    9·1 answer
  • A program runs from start to finish, producing unexpected results, though no error message is received. What most likely occurre
    15·1 answer
  • 50 POINTS! What can be viewed in the Tasks folder? Check all that apply.
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!