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
Joann wants to insert page numbers at the bottom of the pages of her document using the Field option in Quick
ra1l [238]

Answer:

Page under the Numbering category

NumPages under the Document Information category

is the correct answer to the given question.

Explanation:

Following are the points that are mention below that the Joann wanted to insert the page number at the footer of the page of the document with the help of field option .

  • The Page section of the category numbering is insert the page number in the bottom of the page .
  • NumPages in the category option of the Document Information is insert the page number in the bottom of the page .
  • All the other option are not relating to insert the page that's why it is incorrect option .
7 0
3 years ago
Read 2 more answers
When programming, the word "execute" means which of these?
Inga [223]

Answer:

to run!

Explanation:

hope this is helpful!

7 0
3 years ago
Which of the following best describes the protocols used on the Internet?
max2010maxim [7]

Answer:

D: The protocols of the Internet are open and used by all devices connected to the network

Explanation:

There are billions of devices connected to the Internet, and hundreds of different kinds of devices: laptops, tablets, phones, refrigerators, handheld credit card readers, and so on. Protocols (standards) ensure that the variety of devices interact with each other smoothly.  There are a lot of protocols! The Internet was designed with several layers of abstraction that sort the protocols according to what part of the process they support.

5 0
3 years ago
The _________ in an internet are responsible for receiving and forwarding packets through the interconnected set of networks and
raketka [301]

Answer:

routers

Explanation:

<h2><em><u>Fill in the blanks</u></em></h2>

The<u> routers </u> in an internet are responsible for receiving and forwarding packets through the interconnected set of networks and making routing decisions based on knowledge of the topology and traffic/delay conditions of the internet.

3 0
3 years ago
Most networking media send data using _____ in which data is represented by only two discrete states: 0s and 1s.
dlinn [17]

Answer:

i think digital signals

Explanation:

A digital signal is a signal that is being used to represent data as a sequence of discrete values; at any given time it can only take on one of a finite number of values.[1][2][3] This contrasts with an analog signal, which represents continuous values; at any given time it represents a real number within a continuous range of values.

6 0
3 years ago
Read 2 more answers
Other questions:
  • What is primary storage
    11·2 answers
  • A hard drive cannot be partitioned until the device _________ is set.
    15·1 answer
  • What color does Sam obtain when he mixes white with a color? Sam is painting a landscape and needs to paint the sky light blue.
    9·2 answers
  • Is it safe to take apart a computer monitor?
    13·1 answer
  • Which option on the Format tab is used to modify particular portions of the chart?
    12·1 answer
  • What is the setting an alarm clock output??
    10·1 answer
  • PLEASE ANSWER THIS ASAP‼️
    10·2 answers
  • Which list shows a correct order of mathematical operations that would be used by a spreadsheet formula?
    6·1 answer
  • What are the steps to view two different versions of the same document at once?
    11·1 answer
  • and assuming main memory is initially unloaded, show the page faulting behavior using the following page replacement policies. h
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!