# CS 163/164, Fall 2017

## Overview

This lab will introduce and practice with recursion! We will be doing a few tasks, all using recursion - NO LOOPS ALLOWED!
• Problem solving with recursion
You will create an R19 project and class and implement the following interface: IR19.java

### Assignment Overview

Recursion is essentially when a method calls itself, asking for the solution of a smaller instance of the problem.
Two things are vital when using recursion: a base case (or base cases) and the recursive case.

Complete the code for the defined methods according to the pre and post-conditions.

All of these must be recursive and cannot use loops. Think about what the base cases are and what the recursive case is.

Below is test code for you to run and verify with the TA for credit for today's lab.

```public static void main(String[] args) {

R19 rec = new R19();
System.out.println("sumDigits(int x):");
System.out.println("Answer (1234): " + rec.sumDigits(1234) + "   Expecting: 10");
System.out.println("Answer (7): " + rec.sumDigits (7) + "   Expecting: 7");
System.out.println("Answer (6789): " + rec.sumDigits (6789));
System.out.println();

System.out.println("countCannonballs (int x):");
System.out.println("Answer (1): " + rec.countCannonballs(1) + "   Expecting: 1");
System.out.println("Answer: " + rec.countCannonballs (4) + "   Expecting: 30");
System.out.println("Answer (10): " + rec.countCannonballs (10));
System.out.println();

System.out.println("numDigits(int x):");
System.out.println("Answer (1234): " + rec.numDigits(1234) + "   Expecting: 4");
System.out.println("Answer (7): " + rec.numDigits (7) + "   Expecting: 1");
System.out.println("Answer (678900): " + rec.numDigits (678900));
System.out.println();

System.out.println("backString(String s):");