Class MoreRecursionHelper

Object
MoreRecursionHelper

public class MoreRecursionHelper extends Object
This class is where you will be implementing more of your recursive methods.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    combinations(String str, int index, String currStr)
    For this method, we are given a String to rearrange into all possible subsets of the characters recursively.
    int
    pyramidTotal(int rows)
    This method takes a parameter of however many rows of "blocks" our imaginary pyramid is made up of.
    int
    toBinary(int toConvert)
    This method will convert any normal decimal number to its binary representation, so a number like 17 should return 10001.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MoreRecursionHelper

      public MoreRecursionHelper()
  • Method Details

    • toBinary

      public int toBinary(int toConvert)
      This method will convert any normal decimal number to its binary representation, so a number like 17 should return 10001. If you forget what binary numbers are or how they are read, there is a section within your zyBooks on the subject. This method can be deceivingly simple, but you will need to use operators such as modulo, and don't forget about PEMDAS!
      Parameters:
      toConvert - The decimal number that we want to convert.
      Returns:
      Binary representation of initial decimal number.
    • pyramidTotal

      public int pyramidTotal(int rows)
      This method takes a parameter of however many rows of "blocks" our imaginary pyramid is made up of. Each row is made up "blocks" equal to the row number, so row 1 would have 1 block and row 12 would have 12 blocks. You will want to recursively calculate how many total "blocks" make up a pyramid given the rows. For example, 3 would return the sum of 1, 2, and 3, which is 6 and 12 would return 78.
      Parameters:
      rows - The total number of rows our pyramid contains.
      Returns:
      Total number of "blocks" in pyramid.
    • combinations

      public void combinations(String str, int index, String currStr)
      For this method, we are given a String to rearrange into all possible subsets of the characters recursively. Each of these combinations will be printed and the order should not matter. For example, "bed" would print:
      • b
      • be
      • bed
      • bd
      • e
      • ed
      • d
      There are multiple routes of implementing this method recursively, but one of the most common approaches uses a for-loop to work through each character within the provided String.
      Parameters:
      str - The input String.
      index - Index within the current subset
      currStr - The current subset