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
What is VoIP?
xeze [42]

Answer:

D. All of these are correct

Explanation:

VoIP transmits voice data packets over the internet. It is a low-cost option for receiving personal and business calls because it uses existing infrastructure that is the internet to transmit calls, unlike traditional telephone systems that require specialized equipment such as PBXs that are costly.VoIP also offers the ability to have more than one telephone number, as long as the bandwidth is enough, it allows multiple connections at any given time.

7 0
4 years ago
What is the purpose of the "time-to-live" (TTL) field of the IPv4 packet? a. ensures that the packet remains in the network long
Arisa [49]

Answer:

c. it prevents the packet from remaining indefinitely in the network thus helping to prevent network congestion

Explanation:

It prevents the packet from remaining indefinitely in the network thus helping to prevent network congestion

TTL is a value which is shown so that we can estimate that the packet that will tell the network router whether the packet has been in the network for enough time so that it should be discarded from the network or not.

6 0
3 years ago
When you insert an object in a document, word always inserts it as a floating object. true or false.?
wolverine [178]
Not always. If you have text wrapping on, it will snap to the text.
3 0
4 years ago
Write a Java program that accepts an integer number from the user between 20 and 100. Next, divide the number by 12 and determin
Eddi Din [679]
Import java.util.Scanner;
class hola
{
public static void main(String[]args)
{
Scanner x=new Scanner(System.in);
int a=x.nextInt();
int b;
if(a>20&&a<100)
{
b=a%12;
if(b%2==0){
System.out.print("es par"+b);
}
else{
System.out.print("es impar"+b);
}
}
}

}
4 0
4 years ago
What is the full word of"VPN"?​
pantera1 [17]

Answer:

Virtual Private Network.

Explanation:

A VPN helps protect your data when accessing the internet. It usually scrambles your IP location and encrypts your data.

5 0
3 years ago
Read 2 more answers
Other questions:
  • Bill needs to make a presentation in which he has to represent data in the form of a pyramid. Which feature or menu option of a
    14·1 answer
  • Assume the existence of a Building class with a constructor that accepts two parameters: a reference to an Address object repres
    9·1 answer
  • You are boating on a lake. the weather turns bad. what should all passengers do first?
    14·2 answers
  • This is not a factor that you should use to determine the content of your presentation. Your audience your goals your purpose yo
    7·2 answers
  • A(n) _____ uses spatial and nonspatial data and specialized techniques for storing coordinates of networks of lines (roads, rive
    8·1 answer
  • You have created a new DHCP scope with address range 192.168.1.1 to 192.168.1.254. You have five servers configured with static
    8·1 answer
  • In ____, data can move in both directions at the same time, such as with a telephone.
    11·1 answer
  • Which quality allows programmers to modify a program as and when required
    11·2 answers
  • Which scenario is best for an online discussion group?
    5·1 answer
  • Please help with this
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!