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
A security analyst is investigating a call from a user regarding one of the websites receiving a 503: Service unavailable error.
OverLord2011 [107]

Answer:

C. Denial of Service

Explanation:

Denial of service error occurs when the legitimate users are unable to access the system. They are then unable to access the information contained in the system. This can also be a cyber attack on the system in which user are stopped from accessing their personal and important information and then ransom is claimed to retrieve the attack. In such case system resources and information are temporarily unavailable to the users which disrupts the services.

5 0
3 years ago
Olivia started working last year. By April 15th, she will need to prepare and send the Federal government _____.
omeli [17]
Income tax documents
5 0
3 years ago
Read 2 more answers
Bloodborne pathogens travel by way of blood cells and can only be spread by person-to-person contact with infected blood
Eva8 [605]
That is incorrect. It is only contagious if blood is injected into person who is not infected.
5 0
3 years ago
Read 2 more answers
I need app ideas please help​
Artemon [7]

Answer:

I have a few ideas although most are simple and for nothing too useful

1. ghost simulator (you can like haunt people and mess with all their stuff and the more u f with them tge more points and the higher level u get you get more power and more ability to mess with things like eventually you'll be able to possess things and ig the goal wou.d be to either kill the person living in your house or scare them until they run away and there can be little side missions for like extra points and accessories n stuff)

2. my forest (you have workers that make money and the more money you get the more stuff u can buy for your forest and you can customize it and it's pretty much like a therapeutical thing where you can make a pretty forest w mystical creatures and stuff

3. egg (its literally just an egg on the screen that's it there is just an egg)

Explanation:

first things that came to mind I just like brainstorming at these kinda things lmk if u plan on using any aspect of my ideas I'd love to see your app

4 0
3 years ago
Need help with 4.7 lesson practice
OverLord2011 [107]

Answer:

1.a

2.sorry cant read it that wekk

3.c

Explanation:

7 0
3 years ago
Other questions:
  • You are in a library to gather information from secondary sources, and you want to find a current print resource that can supple
    6·1 answer
  • PHOTOSHOP QUESTION:
    14·1 answer
  • Given a string, return a version without the first and last char, so "Hello" yields "ell". The string length will be at least 2.
    13·1 answer
  • Select what's true about packet sniffers. Check All That Apply Legitimate sniffers are used for routine examination and problem
    15·1 answer
  • 7x+ 2x = 14<br>want is (x)?​
    15·1 answer
  • Define foreign key. What is this concept used for?
    6·1 answer
  • An IT systems engineer creates a new Domain Name System (DNS) zone that contains pointer (PTR) resource records. Which zone type
    15·1 answer
  • One standard photo editing software programs for professionals is which of the following?
    11·2 answers
  • What type of error occurred??
    10·1 answer
  • Mention 5 types of assembly language​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!