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]
2 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]2 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 type of electromagnetic wave do cell phones send and receive.
Slav-nsk [51]
?? it should be radio waves but i guess the next best thing is microwaves
4 0
2 years ago
Read 2 more answers
Which of the following is NOT a way the media communicates unrealistic body images?
Leokris [45]

The media communicates unrealistic body image through various ways, which are mentioned in the available options for the question. It definitely digitally alters images that they use for their various publications, and it also provides forums to discuss actor and actresses, including their looks.

The media also often criticizes high-profile individual’s current body condition – whether they are too underweight or too overweight. Thus, the best answer for the question would be (D) promoting all body types.

6 0
3 years ago
Read 2 more answers
Explain the function of different flags in the 8086<br>​
posledela

Answer:

A flag is a piece of fabric (most often rectangular or quadrilateral) with a distinctive design and colours. It is used as a symbol, a signalling device, or for decoration.8086 has 16-bit flag register, and there are 9 valid flag bits.The FLAGS register is the status register in Intel x86 microprocessors that contains the current state of the processor. This register is 16 bits wide. Its successors, the EFLAGS and RFLAGS registers, are 32 bits and 64 bits wide, respectively. The wider registers retain compatibility with their smaller predecessors.

5 0
3 years ago
What is the definition of physical fitness?
Bond [772]
The answer is A:the body’s ability to be efficient during movement.
5 0
3 years ago
Read 2 more answers
Complete the sentence.
Luda [366]
The answer is Tablets
6 0
2 years ago
Other questions:
  • Which fingers do you use to type the following letters rtgvf
    11·1 answer
  • A disadvantage of ethernet??
    6·1 answer
  • A complete traversal of an n node binary tree is a(n)____ "operation if visiting a node is O(1)for the iterative implementation
    5·1 answer
  • A computer is a multipurpose device that accepts input processes data and produces output all according to a series of stored
    8·1 answer
  • ___ is an example of a function prototype.
    12·1 answer
  • What does it mean for a heap to be complete?
    7·1 answer
  • What is the right age to start coding in high school?
    11·1 answer
  • Which symbol would be used in a flowchart to represent a connection to another part of the flowchart on the same page
    15·1 answer
  • Why does my internet keep disconnecting and reconnecting.
    9·1 answer
  • Cybersquatters:_________.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!