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
How can I cancel my subscription I try to go to my account setting and the only thing that pops up is terms of use and change co
Sati [7]

If the only trying that appears is terms of use and change country, that means you are a free user and not a paying subscriber.

So there is no actual subscription to cancel.

If you were a paying subscriber, there would be a cancel subscription option within your account settings.

8 0
3 years ago
Write a multi-threaded program that outputs prime numbers. The program should work as follows: the user will run the program and
Ierofanga [76]

Answer:

The programming code can be found in the explanation part, please go through it.

Explanation:

Code:

#include<stdio.h>

#include<stdlib.h>

#include <pthread.h>

// function check whether a number

// is prime or not

int isPrime(int n)

{

// Corner case

if (n <= 1)

return 0;

// Check from 2 to n-1

for (int i = 2; i < n; i++)

if (n % i == 0)

return 0;

return 1;

}

void* printPrimes(void *vargp)

{

int *n = (int *)vargp;

int i=0;

for (i=2;i<=n;i++)

{

if (isPrime(i)) printf("%d\n", i);

}

}

// Driver Program

int main(int argc, char* argv[])

{

int n = atoi(argv[1]);

pthread_t tid;

pthread_create(&tid, NULL, printPrimes, (void *)n);

pthread_exit(NULL);

return 0;

}

4 0
3 years ago
PLEASE BE AWARE OF THESE BITLY LINKS THAT ARE GOING AROUND THEY ARE BOTS TRYING TO STEAL YOUR INFORMATION!!!!
bixtya [17]

Answer:

oh thanks!

Explanation:

3 0
3 years ago
Read 2 more answers
Describa las etapas del arranque de viruta
blondinia [14]

Answer:

Las virutas son partículas que se eliminan mecánicamente de una pieza de trabajo mecanizada. En el contexto de la tecnología de fabricación, especialmente el mecanizado, el término se refiere principalmente a virutas de metal; En principio, sin embargo, las virutas se crean en todo tipo de mecanizado de cuerpos sólidos. Las astillas de madera son el resultado de la carpintería. Cuando se mecanizan plásticos, se crean virutas, así como cuando se mecanizan materiales minerales, cristalinos o amorfos como el vidrio, que a menudo se realiza mediante esmerilado.

7 0
3 years ago
Two technicians are discussing MAP sensors. Technician A says that the MAP sensor should be replaced if anything comes out of th
anygoal [31]

Answer:

Both are correct.

Explanation:

Both technicians are correct in this scenario. Technician A point of view is correct as well as technician B.

3 0
3 years ago
Other questions:
  • When does state law require drivers to use their headlights (6)
    11·2 answers
  • What laptops can you get for 2500$ and should mostly using Microsoft applications.
    14·2 answers
  • "Write an iterative function iterPower(base, exp) that calculates the exponential baseexp by simply using successive multiplicat
    10·1 answer
  • In 1964 in London, Ontario one could buy a chili-dog and a root beer for $1.25, today the same chili dog and root beer cost $5.0
    8·1 answer
  • A good way to assess your CPU usage is to:_______.
    13·1 answer
  • Define a class called Counter. An object of this class is used to count things so it records a count that is a non-negative whol
    12·1 answer
  • Well the last week has been kind of terrible...
    9·2 answers
  • 1. Write a generic method that compares its 2 arguments using the equals method and returns true if they are equal and false oth
    8·1 answer
  • One of the primary principles of the Rapid Application Development methodology is early prototyping of the _______ in the develo
    6·1 answer
  • Helpppppppppppppppppppppppppppppppp
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!