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 cell address indicates the intersection of the first row and the first column in a worksheet?
Roman55 [17]
The answer is A1. 

The columns are arranged alphabetically, and the rows are ordered numerically. The cell address states the column, a letter, followed by the row, a number. The first cell address, the top-left cell of the sheet, is A1
7 0
3 years ago
Read 2 more answers
Why do you think it is important to consider ethical considerations when reviewing technology and assessing the impact of partic
IgorLugansk [536]

Answer:

The correct answer should be: "It is important to reaffirm and test technologies' importance and impact to society in order to reflect upon their benefits or damages to the environment".

Explanation:

Technologies have a major importance in society nowadays, although they also have a great impact in the environment, whether for good or not. The fact is that reviewing and assessing technologies' importance and impact are necessary to test and garantee if they have been developed in an environmental friendly manner or with no worries for natural resources and society. Therefore, any technology must be ethical in terms of improving society with no damages, or as least as possible, to the environment.

(ps: mark as brainliest, please?!)

7 0
3 years ago
Lập trình web truy vấn csdl và hienr thị ra màn hình danh sách các bản ghi
almond37 [142]

Answer:

ExplanatOverfishing occurs "when more fish are caught than the population can replace through natural reproduction," according to the World Wildlife . Once this occurs, the species is no longer "sustainable." Eighty-seven percent of all the world's fish stocks that we know about are at the "breaking point," according to the Environmental Defense Fund (EDF).

ion:

3 0
2 years ago
The dome of Hagia Sophia rests on these curving, triangular features of Byzantine architecture called __________.
kipiarov [429]

Answer:

pendentives

Explanation:

4 0
3 years ago
The system tray contains _____.
xeze [42]

Answer:

the system tray is located in the Windows Taskbar (usually at the bottom next to the clock) and contains miniature icons for easy access to system functions such as fax, printer, modem, volume, and more. Double click or right click on an icon to view and access the details and controls.

Explanation: in window 95

7 0
3 years ago
Read 2 more answers
Other questions:
  • What file formats can you safely use in a video presentation
    14·1 answer
  • How to jail break iphone 7 with <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7617023602">[email&#160
    11·2 answers
  • People use a computer connected to the internet to manage financial accounts
    15·1 answer
  • A ________ allows users to add, remove, or edit its content.
    10·2 answers
  • What are the five layers in the internet protocol stack? What are the principal responsibilities of each of these lay?
    9·1 answer
  • Assume that a picture is represented on a monitor screen by a rectangular array containing 2048 columns and 1536 rows of pixels.
    12·1 answer
  • Which of the following best meets the requirements of a strong password?
    5·2 answers
  • Lukas entered the date 9-17-2013 in an Excel workbook. He wants the date to appears as “Tuesday, September 17, 2013.” Instead of
    12·1 answer
  • Do you think it’s better for a young designer to use free, open-source art programs or to pay for commercial programs? Explain y
    14·1 answer
  • Create a basic program that accomplishes the following requirements: Allows the user to input 2 number , a starting number x and
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!