Unit 4D - Code Practice for Recursion

From CS Awesome 2CC BY-NC-SA 4.0Original page

Java1 class period1 exercise2 graded tests

Files

README.mdDownload

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-RecursionPractice1 folder and edit Recursion.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

In class

  1. Students read README.md.
  2. Students do exercise 01 in its folder, pressing Run to try their code.
  3. 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

FolderFileGradingTests
01-RecursionPractice1Recursion.javaAutograded2

Teachers can download a reference solution after signing in.