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]
2 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]2 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
While interoperability and unrestricted connectivity is an important trend in networking, the reality is that many diverse syste
iogann1982 [59]

Answer:

Middleware

Explanation:

In today's technology like networking, software development, web development, etc, there is a need for connectivity. The problem at hand is the variation of the tech brands which results in the difference in operating systems, applications, and connectivity protocols. This problem is solved with the introduction of Middleware.

Middleware is the solution to conflicting software applications, interconnectivity between various tech platforms. It promotes cross-platform interactions.

6 0
3 years ago
Every application program has a _______________ segment
Natali5045456 [20]
"Main" goes in the blank. For example in C++ all of your code goes in the main function.
4 0
3 years ago
Bcghxdfghncfghndfgxdfgjfjgktyerdgftguj
IgorLugansk [536]

Answer:

Okay

Explanation:

4 0
3 years ago
Read 2 more answers
A user complains that her computer is performing slowly. She tells you the problem started about a week ago when new database so
motikmotik

Answer/Explanation:

It is best to use Performance Monitor and Process counters to observe performance.

Cheers

6 0
2 years ago
Which social networking site became a gaming platform after 2009
PtichkaEL [24]

Answer:

Should be Hi5

have good day

3 0
3 years ago
Other questions:
  • Which innovation allowed for the mass production of goods? A. Cotton gin B. Sewing machine C. Industrial lubricator D. Interchan
    6·1 answer
  • Explain the difference between an i/o‐bound process and a cpu‐bound process.
    12·1 answer
  • 11.
    11·1 answer
  • What are the advantages of homogenation
    5·1 answer
  • You are a network technician for a small corporate network. It's been decided that the office needs a wireless network for emplo
    6·1 answer
  • A______ is a graphical representation of numeric data.
    8·1 answer
  • CodeHS 3.4.5. What is the code for four colored triangles.
    8·1 answer
  • What does ctto mean?
    11·2 answers
  • A USB device used to transfer photos from the memory card to a hard drive is called a _____.
    5·2 answers
  • Kaitlin likes a particular design theme, but she is not sure about every single color for bullets, backgrounds, etc. found in th
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!