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
Suppose that each country completely specializes in the production of the good in which it has a comparative advantage, producin
djverab [1.8K]

Answer:

In  this case, the country that produces rye will produce 24 million bushels per week, and the country that produces jeans will produce 64  million pairs per week.

Explanation:

Total labor hour = 4 million hour

Number of bushes produce in 1 hour = 6

⇒total bushes produce = 6*4 = 24 million

∴ we get

The country that produces rye will produce 24 million bushels per week

Now,

Total labor hour = 4 million hour

Number of pairs produce in 1 hour = 16

⇒total bushes produce = 16*4 = 64 million

∴ we get

The country that produces jeans will produce 64  million pairs per week.

5 0
3 years ago
All of these acts performed when doing an oil and filter change except ?
Nat2105 [25]
B. Loosening the drain plug with a screwdriver
6 0
3 years ago
Read 2 more answers
A device capable of copying a graphic, document, or other object is called a
Amiraneli [1.4K]
A printing press or printer
5 0
3 years ago
Read 2 more answers
In computing the present value of the lease payments, the lessee should a.use both its incremental borrowing rate and the implic
JulijaS [17]

Answer:

The answer is  "Option a"

Explanation:

This payment is equivalent to the regular rent formally specified by the same contract that grants the member the rights for a specified time. It used both the nominal lending rate and the lessor's conditional value,  which provides the lower implied rate, and wrong choices can be described as follows:

  • In option b, It is wrong because in this we assume the implicit rate is lessee.
  • Option c and Option d both were wrong because It doesn't use the Iterative credit rate.

6 0
3 years ago
What is cpu write its parts<br>​
aev [14]

Answer:  a CPU is a central processing unit. They’re responsible for creating and executing instructionsl

Explanation:

6 0
3 years ago
Other questions:
  • Software that was designed to serve the needs of a specific company or organization is called:
    5·1 answer
  • The most likely reason that company computers connected to the Internet should use anti-virus protection software is..?
    5·1 answer
  • What is the output of the following Java code?int x = 1;do{System.out.print(x + " ");x--;}while (x &gt; 0);System.out.println();
    14·1 answer
  • Which note-taking method quickly captures and organizes information?
    9·2 answers
  • A standard for compressing music into computer files that can be easily exchanged on the Internet is called a(n) ______. A. musi
    5·1 answer
  • If you do not use the mini toolbar, it remains on the screen. _______________​ Group of answer choices True False
    8·1 answer
  • What is connectivity?
    15·2 answers
  • An epic games service is unavailable at the moment
    8·1 answer
  • A friend of mine had a samsung j2 phone and someone with a iphone placed something in her phone she thought was malware in her p
    7·1 answer
  • What would be printed to the screen when the following program is run?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!