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 is a office buttom?
SpyIntel [72]
The Microsoft button was exclusively used in the 2007 versions of word, excel, powerpoint, access and outlook. It has all of the different options like to save, print, open ect. It was located in the top left hand corner of the screen. It looked a bit like this (see attachment).

3 0
3 years ago
Which part of the website address is its top-level domain name?
mr Goodwill [35]
The top-level domain is usually .com, .org, .net, and many more.
4 0
3 years ago
If I have an Animal superclass with a Mammal subclass, both concrete and both having a method called eat() with identical signat
Katarina [22]

Answer:

(c) the dynamic type of reference will determine which of the methods to call.

Explanation:

Polymorphism in Object Oriented Programming typically means the same method name can cause different actions depending on which object it is invoked on. Polymorphism allows for dynamic binding in that method invocation is not bound to the method definition until the program executes.

So in the case of Animal superclass and Mammal subclass, both having a method called eat() with identical signatures and return types, depending on which reference, the correct method eat() will be called dynamically upon execution.

For example, if we have the following;

================================

<em>Mammal mammal = new Animal();</em>

<em>mammal.eat()</em>

================================

The eat() method that will be called is the one in the Mammal subclass.

However, if we have;

================================

<em>Animal animal = new Animal();</em>

<em>animal.eat()</em>

================================

The eat() method of the Animal superclass will be called.

5 0
3 years ago
ANWSER ASAP
Alona [7]

Answer:

Cell wall more selectively controls what goes in and out of the cell, it gives a plant cell its shape, is rigid.

6 0
2 years ago
Many who move to business-oriented information security were formerly__________ who were often involved in national security or
kirill [66]

Answer:

The information security function

Explanation:

Many who move to business-oriented information security were formerly_____ who were often involved in national security or cybersecurity . All of the above The information security function

5 0
2 years ago
Other questions:
  • How to make a sad face on keyboard using alt?
    5·2 answers
  • I can create spreadsheets in Google Draw. False True
    14·2 answers
  • Predictive coding software leverages .............................when experts review a subset of documents to teach the softwar
    15·1 answer
  • The benefits for a cad proram is: (points : 2) 1 accuracy 2 repeatability 3 simplicity 4 all of the above
    9·1 answer
  • A 'array palindrome' is an array which, when its elements are reversed, remains the same (i.e., the elements of the array are sa
    6·1 answer
  • Use fuel with the _____________ rating recommended by your vehicle manufacturer. A ) Converter B) Emission C) Exhaust D) Octane
    9·2 answers
  • The database must be carefully planned to allow useful data manipulation and report generation.
    10·1 answer
  • Typing with capital letters and exclamation points in an e-mail is an example of
    12·2 answers
  • Prokaryotes are __________________ and include ________________________.
    8·1 answer
  • How can I master networking my home/business computer(s) - Tv's - iot devices and make the whole system as secure as possible?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!