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 are some of these new iPad extras? One is the iMarker. Crayola teamed up with another company to make it. It costs $29.99.
saul85 [17]
Another one is iMovie which allows you to edit and cut things.
5 0
3 years ago
Give an explanation of one network connection (it will every helpful​
charle [14.2K]

Answer:

WiFi, Ethernet, Broadband, Dial-up. Any of those.

Explanation:

Network connections are all different. Those listed are some of the many examples of network connections.

7 0
3 years ago
A paradigm innovation occurs when:
Viktor [21]
B. Because major shifts in thinking can cause change.
4 0
3 years ago
A friend has a CD of one of your favorite artists and has offered to let you copy it.
creativ13 [48]
No; copyright laws protect this artist's rights and I need to purchase the CD if I want it.  

This is due to copyrights being applied at the time of fixation.  In other words, as soon as the words or lyrics have been placed on paper, recorded or put in a computer the ARTIST is protected.
6 0
3 years ago
A type of specialty processor devoted exclusively to protecting your privacy.
drek231 [11]
 Cryptoprocessor would be it.
8 0
4 years ago
Read 2 more answers
Other questions:
  • As you move the click and type pointer around the document, the icon changes to represent ____________________ that will be appl
    10·2 answers
  • How do i unblock website on my school computer
    7·2 answers
  • What is an identified component of a software program that might allow a hacker or other intruder to gain entry and control of a
    10·2 answers
  • The first step to accurate coding is to identify the ___________ in the diagnostic statement.
    7·1 answer
  • Which of the following is a key feature of SmoothWall? Weak traffic graphs and bandwidth bars Universal Plug and Play support DM
    7·1 answer
  • Difference between ancient and modern mode of information <br> transmission
    12·1 answer
  • Difrent between computer and computer system​
    9·1 answer
  • I’m gonna ask this again because I REALLY need an answer.
    10·2 answers
  • What is the base of a number system?
    8·1 answer
  • We can improve our knowledge and skills on animals and fish raising with the use of internet​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!