Recursion – 40 course points

This assignment consists of writing a function that appends strings recursively.

Refer to our Programming Assignments FAQ for instructions on how to install VSCode, how to use the command line and how to submit your assignments.

Start your assignment early.

Programming

Write 1 program and submit on Autolab.

  • We provide a zip file in Autolab containing RecursiveAppend.java.
  • For each problem UPDATE and SUBMIT the corresponding file.

Observe the following rules:

  1. DO NOT add any import statements
  2. DO NOT add the project statement
  3. DO NOT change the class name
  4. DO NOT change the headers of ANY of the given methods
  5. DO NOT add any new class fields
  6. DO NOT use System.exit()
  7. DO NOT print inside the function.

Recursive Append  

On RecursiveAppend.java write a recursive function appendNTimes that receives two parameters, a string and an integer. The method appendNTimes returns the original string appended to the original string n times.

  1. public static String appendNTimes (String original, int n)
  2.  
  3. Examples:
  4. appendNTimes("cat", 0) returns “cat”
  5. appendNTimes("cat", 1) returns “catcat”
  6. appendNTimes("cat", 2) returns “catcatcat”
  7.  
  8. The following restrictions apply to method appendNTimes:
    • YOUR CODE MUST BE RECURSIVE
    • Do not use loops (while, do/while, or for).
    • Your code must return a string without extra space, comma or any other character that is not in the original string
    • DO NOT print anything inside the function.

    We provide a test client (main method) to test your appendNTimes method. Autolab will ignore your main method.

Before submission

Collaboration policy. Read our collaboration policy here.

Submitting the assignment. Submit RecursiveAppend.java via the web submission system called Autolab. To do this, click the Assignments link from the course website; click the Submit link for that assignment.

Getting help

If anything is unclear, don’t hesitate to drop by office hours or post a question on Piazza.

  • Find instructors office hours here
  • Find tutors office hours in Canvas -> Tutoring, RU CATS
  • Find head TAs office hours here
  • POST on Piazza in Canvas -> Piazza
  • In addition to office hours we have the CAVE (Collaborative Academic Versatile Environment), a community space staffed with lab assistants which are undergraduate students further along the CS major to answer questions.