Class MoreRecursionHelper
Object
MoreRecursionHelper
This class is where you will be implementing more of your recursive methods.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.
-
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
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
- Parameters:
str
- The input String.index
- Index within the current subsetcurrStr
- The current subset
-