Recursion

Recursion

Purpose


The purpose of this
in-lab is to give you experience with recursion.

Partners

This is an individual
assignment, though collaboration (not solution sharing) is allowed.

Preliminaries

Create a BlueJ project
named Inlab9 on your lab computer. Place the following files
into this project:


  • Driver.java

  • Recursion.java



Assignment

Complete the following
two methods in the Recursion class as described below so that when the program
is run, this output is produced. Do not modify the Driver
class at all.

convertToBinary(int
number)

The method should use
recursion to convert a decimal number into its binary equivalent. For example,
decimal 4 is equivalent to binary 100.

You may assume that when
the method is first called, number is greater than or equal to
1.

largestArrayItemAuxiliary(int
[] numbers, int index)

The method should use
recursion to find the largest item stored in an array of integers. The first
time this method is called, index is 0.

You may assume that the
array always contains at least one item.

 

 
Powered by