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
neonofarm [45]
3 years ago
15

Write a function in Java that implements the following logic: Given a string and an int n, return a string made of n repetitions

of the last n characters of the string. You may assume that n is between 0 and the length of the string, inclusive.
Computers and Technology
1 answer:
liubo4ka [24]3 years ago
8 0

Answer:

public class RepeatedString

{

public static void main(String[] args) {

 

 System.out.println(repeatString("apple", 3));

}

public static String repeatString(String str, int n) {

    String newString = str.substring(str.length()-n);

    System.out.println(newString);

    String ns = "";

    for(int i=0; i<n; i++) {

        ns += newString;

    }

    return ns;

}

}

Explanation:

- Create a function called repeatString that takes two parameter

- Get the last n characters of the string using substring function, and assign it to the newString variable

- Initialize an empty string to hold the repeated strings

- Initialize a for loop that iterates n times

- Inside the loop, add the repeated strings to the ns

- When the loop is done, return ns

- Inside the main, call the function

You might be interested in
What does a computer use to determine if an ip address of another computer is on the same network or a different network?
Radda [10]
It uses it's routing table. If the destination is on the same network, it transmits directly via the MAC address. If the destination is on another network, it transmits to whatever the table says for that network. For desktops it's usually a default address of the router on the computer's network.
6 0
3 years ago
-FOR EXCEL AND WILL GIVE BRAINLIEST-
kaheart [24]

Answer:

I believe the answer is B. Click currency style button on the formatting toolbar

Explanation:

4 0
3 years ago
The storage device which is not usually used as secondary storage is 1 point a) Semiconductor Memory b) Magnetic Disks c) Magnet
marshall27 [118]

Answer:

a) Semiconductor Memory

Explanation:

A primary storage device is a medium that holds memory for short periods of time while a computer is running

Semiconductor devices are preferred as primary memory.

ROM, PROM, EPROM, EEPROM, SRAM, DRAM are semiconductor (primary) memories.

7 0
3 years ago
What is an algorithm?A. a series of actions that solve a particular problem.B. an English description of a problem to be solved.
Elena L [17]

Answer:

A. a series of actions that solve a particular problem.

Explanation:

An algorithm refers to step by step instructions used to fix a problem and they are used for tasks like make calculations and process data. Algorithms are important for computers to be able to process information as they provide the instructions on how a task has to be performed. According to this, an algorithm is a a series of actions that solve a particular problem.

4 0
3 years ago
Assume that a function with this header: function amountSaved(price, discountRate, salesTaxRate) already exists. Write a single
Levart [38]

Answer:

let saved = amountSaved(12, 0.9, 0.06);

Explanation:

By presuming there is a JavaScript function <em>amountSaved() </em>that takes three input parameters, <em>price</em>, <em>discountRate</em> & <em>salesTaxRate</em>.  To call the function, just simply write the function name, <em>amountSaved</em> followed with a pair of parenthesis. Within the parenthesis, include three testing values, 12, 0.9, 0.06 as arguments. These argument values will be held by the three parameter <em>price</em>, <em>discountRate</em> and <em>salesTaxRate</em>, respectively.

The function will operate on the three input values and return the result to the main program where the returned result is assigned to a variable name <em>saved</em>.

4 0
3 years ago
Other questions:
  • Kai is a software engineer who started his own IT consulting firm. His friend, Catalina, is the owner of a store that sells offi
    13·2 answers
  • Assume s is a string of lower case characters.
    15·1 answer
  • If the processor has 32 address lines in its address bus; i.e. 32-bit address range, what is its address space or range; i.e. wh
    10·1 answer
  • A Turing machine with stay put instead of left is similar to an ordinary Turing machine, but the transition function has the for
    11·1 answer
  • Who has a relationship like this quote?
    5·2 answers
  • Which term describes an event where a person who does not have the required clearance or access caveats comes into possession of
    15·2 answers
  • Write a java program to print the following series: <br>1 5 9 13 17...n terms​
    13·2 answers
  • The following program is suppose to use the sin() function in the math library and write out an input's absolute value over an i
    12·1 answer
  • Match each definition with the term it describes. A(n) ______ provides identification and addressing information for computers a
    5·1 answer
  • Which of the following statements are true about mobile app development? Select 3 options.
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!