Question

don't use System.exit() please

don't use System.exit() please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Explanation:

Here is the code which has the method appendNTimes in bold taking a string original and the integer n.

It returns the String concatenated n times recursively.

feel free to comment if you need any help!

Code:

public class Main
{
public static String appendNTimes(String original, int n)
{
if(n==0)
return "";
  
return original + appendNTimes(original, n-1);
  
}

   public static void main(String[] args) {
       System.out.println(appendNTimes("cat", 3));
   }
}

Output:

catcatcat Program finished with exit code 0 Press ENTER to exit console.

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!

Add a comment
Know the answer?
Add Answer to:
don't use System.exit() please
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT