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
Think about the pseudocode that you developed for your adventure game in this unit. Would it have been easier to create a flowch
katovenus [111]

Answer:

it may not be easy

Explanation:

because am using a phone not a cuputer

5 0
2 years ago
Which nation has a command economy
Over [174]

Answer:command economy is a key feature of any communist society. Cuba, North Korea, and the former Soviet Union are examples of countries that have command economies, while China maintained a command economy for decades before transitioning to a mixed economy that features both communistic and capitalistic elements

5 0
3 years ago
Read 2 more answers
Specifically, you will write two policies to ensure web server software and web browsers are secure. Your policy statements will
erik [133]

Answer:

Navigate to Prohibit Software from the Inventory tab. This will list the details of all the software that are already prohibited.

Click Add Prohibited Software. This will open the Add Prohibited Software dialog listing all the software detected in the managed computers. You should have scanned the Windows systems at least once to have the details of the software here.

Select the software that you wish to prohibit and move them to Prohibited List.

Note: In case you have grouped certain software and you are adding that Software

4 0
2 years ago
I don't know my password to brainly
garik1379 [7]
Only thing I can think of making a new account I’ve had to make 3 accounts sadly
7 0
3 years ago
Read 2 more answers
What are real online jobs any one of any age can get pays weekly by Pay<br> Pal
ASHA 777 [7]

Answer:

An online lesson will be good.

8 0
2 years ago
Other questions:
  • You should use _____ software for writing a letter.
    10·1 answer
  • The listing of a directory shows certain files with permissions set to rwsr-xr-x. what does this indicate?
    12·1 answer
  • Oracion con punto focal​
    6·1 answer
  • Help me plzzzz ASAP T-T and it's Cyber Security but my last day of school is tomorrow and I'll graduate in June 24 so plzzzzz I
    12·1 answer
  • Pig Latin is ______ and fits very naturally in the pipeline paradigm while SQL is instead declarative.
    7·1 answer
  • Teenagers and their parents will never understand each other-the generation gap is too big. Its for my grade 11 English speech​
    10·2 answers
  • Viruses and Malware Complete the case project on page 82 of the textbook by researching two types of viruses, two types of malwa
    13·1 answer
  • Which shortcut keys can be used to duplicate a slide?
    15·1 answer
  • The banner on the front page of a newsletter that identifies the publication is the:.
    11·1 answer
  • The layer of the ISO/OSI responsible for source to destination delivery.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!