Unit 4D - Code Practice for Recursion
From CS Awesome 2CC BY-NC-SA 4.0Original page
Java1 class period1 exercise2 graded tests
Files
Unit 4D - Code Practice for Recursion
Each coding exercise has its own folder. Open its .java file and press Run to try it. Run Tests checks every graded exercise in this lesson at once.
Exercise 1
Replace the “ADD CODE HERE” below with the code to complete the findSum method. The method should take the sum of every value that is less than or equal to n. For example, findSum(3) should return 6. The output of the program should be 15.
Open the
01-RecursionPractice1folder and editRecursion.java. Press Run to try it; Run Tests checks it (2 tests).
If you would like to try writing recursive methods check out the recursion problems at CodingBat at http://codingbat.com/java/Recursion-1.
For teachers
Unit 4D - Code Practice for Recursion
Students read CSAwesome2's “Unit 4D - Code Practice for Recursion” in CS Room and work through its 1 Java coding exercise.
- Time: 1 class period
- Tests: 2 in 1 graded exercise, set up for you when you import the lesson
Goals
- Practice for Unit 4: Data Collections.
Before class
- Import the lesson into your class from the Lessons page, or with New assignment → Use a lesson. It arrives as a draft with its tests already set up.
- Publish it.
- The original page is on CS Awesome: https://runestone.academy/ns/books/published/csawesome2/recursionCodePractice.html
- CS Awesome's own teacher materials: the CS Awesome teacher site
In class
- Students read
README.md. - Students do exercise 01 in its folder, pressing Run to try their code.
- Run Tests checks every graded exercise at once; scores appear in the Gradebook. Grading uses your copy of the tests, so a student who edits theirs does not change the grade.
Exercises
| Folder | File | Grading | Tests |
|---|---|---|---|
01-RecursionPractice1 | Recursion.java | Autograded | 2 |
Teachers can download a reference solution after signing in.