logo Practice-It logo

repeatQuote

Language/Type: Java method basics println
Author: Marty Stepp (on 2011/01/05)

Write a method named repeatQuote that accepts a String s and an integer n as parameters and outputs the string s repeated n times, separated by colons, with backslashes around the overall line of output. For example, the call:

repeatQuote("hello", 4)

should produce the following console output:

\hello:hello:hello:hello\

The number n of times to repeat can be any integer. If it is less than or equal to 0, print nothing between the backslashes. The calls:

repeatQuote("goodbye", 1);
repeatQuote("booyah", 0);

should produce the following console output:

\goodbye\
\\
Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.