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
4. What is the formula for calculating the file size?
Verizon [17]
Step 2: Multiply total number of pixels by the bit depth of the detector (16 bit, 14 bit etc.) to get the total number of bits of data. Step 3: Dividing the total number of bits by 8 equals the file size in bytes. Step 4: Divide the number of bytes by 1024 to get the file size in kilobytes.
7 0
3 years ago
A programming error that causes a program to generate incorrect results due to failing to use the proper combination of statemen
tino4ka555 [31]

Answer:

Logic error.

Explanation:

Logic error is that type of error in the programming language in which the outcome of the program is incorrect due to the fault on implementing the logic in the program by the programmer, it gives output but that output is incorrect.

<u>For example</u>:

If the programmer wants to create the program of the greater than and he implements wrongly '>' to '<' then the following program returns output but that output is incorrect.

7 0
4 years ago
What does VERONIcA stand for?
kompoz [17]
Very Easy Rodent-Oriented Netwide Index to Computerized Archives
5 0
4 years ago
Read 2 more answers
Plz plz plz subsribe to my channel, CookieFunTime
Nesterboy [21]

ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok

7 0
3 years ago
Document could not be saved bad file handle
creativ13 [48]
To help fix this problem try reviewing the file and opening it on your own when your sure its good on your side then try to save it if all else fails make a new one
8 0
4 years ago
Other questions:
  • What are the correct steps to find the system specifications such as the amount of ram or system type for windows 7 machine?
    5·1 answer
  • You're familiar with the story of Hansel and Gretel, so when you decide to go exploring you always make sure to keep track of wh
    14·1 answer
  • If I want to make it look like slide number one is turning a page to slide number two, what effect needs to be applied?
    13·1 answer
  • CORRECT ANSWER GETS BRAINLIEST
    8·2 answers
  • Core to resource management system is the _________that coordinates the server hardware.
    8·1 answer
  • ¿Por qué en Colombia la mayoría de las empresas no son automatizadas (manejadas por computadoras y robots?
    15·1 answer
  • The following questions requires manipulation an analysis of String objects. a. Create a class named String_Manipulation with a
    6·1 answer
  • Write a complete method to create an array of random integers. The method takes in three integer parameters: the array size, the
    9·1 answer
  • How to reset windows 7 password without logging in
    14·2 answers
  • Wml script is used in? ​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!