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
To locate all locations in a document with the word "employer" and replace it with "company," you should use the _____ function.
grandymaker [24]
That should be the replace function which performs word replacements in documents.
6 0
4 years ago
Two of the major sources used today for obtaining information to create computer maps are satellites and _____________.
krek1111 [17]
The global positioning system
5 0
4 years ago
How to learning algothrim bett
Stells [14]
The GCSE Computing MOOC (created with Cambridge University Press and Raspberry Pi) can be used either as a course or a flexible teaching resource,
8 0
4 years ago
Which instruction in this algorithm would be considered a loop structure? will mark u brainliest 25 points
Mazyrski [523]
I don’t know if I am right but I think it d am i right
6 0
3 years ago
Every UNIX and Linux system contains full documentation of UNIX commands in the _____ pages.
Rashid [163]
Full documentation in the man pages.
8 0
4 years ago
Other questions:
  • When a class contains a pointer to dynamically allocated memory, it is a good idea to equip the class with?
    9·1 answer
  • A range of cells can be converted into an Excel ________ so that the data can be analyzed
    7·1 answer
  • What are the Predictive tasks in Data Mining?
    13·1 answer
  • Janice is making her resume in which section should she include information about her previous employers , positions held , and
    15·1 answer
  • Microsoft's Xbox operating system provides Xbox programmers with a set of common standards to use to access controllers, the Kin
    15·1 answer
  • Error: 404 Not Found <br>The resource that you requested does not exist on this server.
    14·2 answers
  • RrayList Mystery Consider the following method:
    9·1 answer
  • 20. A computer freezes at odd times. At first, you suspected the power supply or overheating, but you have eliminated overheatin
    6·1 answer
  • 01000111 01110101 01100101 01110011 01110011 00100000 01110111 01101000 01100001 01110100 00111111
    13·1 answer
  • Buying the newest phone as soon as it is released when your current phone works perfectly is not a good idea for all but which o
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!