Class RecursionHelper
Object
RecursionHelper
This class is where our functionality and implmentations come from.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintarmstrongNumber(int num, int total) This recursive method takes two int parameters.booleanpalindromeChecker(String str) This recursive method takes a String parameter and checks whether the provided String is a palindrome.reverseString(String str) This recursive method takes one parameter, a String.
-
Constructor Details
-
RecursionHelper
public RecursionHelper()
-
-
Method Details
-
reverseString
This recursive method takes one parameter, a String. You can probably imagine what it does too, it just reverses the String. So if we provided "yield", the return value would be "dleiy". Remember for each of these recursive methods, you will need to call the method in itself, and establish a base and recursive case. For this specific method, you may want to use the String.substring() method.- Parameters:
str- Holds current value of String- Returns:
- Reverse String
-
armstrongNumber
public int armstrongNumber(int num, int total) This recursive method takes two int parameters. The first, num, is what is initially provided by the user, the second, total, should be your current total throughout your recursive calls. The returned value should be the summation of each digit in num, cubed. Armstrong numbers are numbers that each digit can be cubed and then summed, this sum equals the original number. For example, with 153, our three digits are 1, 5, and 3. If we take the cube of 1, 5, and 3, we get 1, 125, 27 taking those cubes and adding them together we are left with 153, our original number. Each recursive call in this method should examine one digit, so for 153, on our first call we should focus on 3, for our second call, 5. The Math.pow(number, power) is useful method that returns number^power. You could also just say number*number*number too.- Parameters:
num- Provided by user, then can be used for recursive calls.total- Running sum of each digit, cubed.- Returns:
- The total, which can be compared against the original input.
- See Also:
-
palindromeChecker
This recursive method takes a String parameter and checks whether the provided String is a palindrome. Depending upon whether the String was a palindrome return true or false. For example, "tacocat" would return true, "sponge" would not. The String charAt and substring methods may help you in this method!- Parameters:
str- String to be checked- Returns:
- True or false.
- See Also:
-