Question
this can be done in one class or two separate classes,in java thanks!

You will implement and test several short recursive methods below. With the proper use of recursion, none of these methods sh
5. A Fractal Pattern Examine this pattern of stars and blanks, and write a recursive method that can generate patterns such a
6. Palindromes A palindrome is a string that is the same when reversed. For example, abba is a palindrome. Here is a math l
You will implement and test several short recursive methods below. With the proper use of recursion, none of these methods should require more than a dozen lines of code. Test all these in the same class. Keep adding methods and testing until all are working
5. A Fractal Pattern Examine this pattern of stars and blanks, and write a recursive method that can generate patterns such as this: With recursive thinking, the method needs only seven or eight lines of code (including two recursive calls). Your method should look like this: public static void pattern(int n, int i) // Precondition: n is a power of 2 greater than zero /Postcondition: A patten based on the above example has been //printed. The longest line of the pattern has // n stars beginning in column i of the output. For example, Il The above pattern is produced by the initially calling pattern(8, 0) Hints: 1. You only need to check that n> 0. You do not need to check that n is a power of 2 2. There is no space before the first star on the first line. There are 2 spaces before the star on the 3rd line and 4 spaces before the star on the 4h line, etc Think about how the pattern is a fractal (a never-ending pattern). Fractals are created by repeating a simple process over and over in an ongoing feedback loop See if you can find two smaller versions of the pattern within the larger pattern. Here is some code that may be useful within your recursive method 3. 4. 5. A loop to print exactly i spaces: for (k-0; k
Comments
    0 0
    Add a comment Improve this question Transcribed image text
    Answer #1

    public static int factorial(int n) if(n ## 1) // base case return 1; // calling recursively with 1 less and multiplying n ret

    CODE

    class Main {

    public static int factorial(int n)

    {

    if(n == 1) // base case

    return 1;

    // calling recursively with 1 less and multiplying n

    return n*factorial(n-1);

    }

    public static double pow(double base, int exponent)

    {

    if(exponent == 1) // base case

    return base;

    // calling recursively with 1 less and multiplying base

    return base*pow(base, exponent-1);

    }

    public static void main(String[] args) {

    System.out.println(factorial(5));

    System.out.println(pow(3.0, 4));

    }

    }

    OUTPUT

    120
    81.0

    // We are allowed to answer 2 coding questions only. Please post accordingly.

    Add a comment
    Know the answer?
    Add Answer to:
    You will implement and test several short recursive methods below. With the proper use of recursi...
    Your Answer:

    Post as a guest

    Your Name:

    What's your source?

    Earn Coins

    Coins can be redeemed for fabulous gifts.

    Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
    Similar Homework Help Questions
    • implement and test several recursive methods below. Test all these in the same program. Keep adding...

      implement and test several recursive methods below. Test all these in the same program. Keep adding methods and testing until all are working.(java) 1.A recursive method to find the sum of all elements of an integer array. The method should have 2 parameters. The array and where to start in the array. Example of initial call: int sum = sumOfValues(array, 0); 2.A recursive method to find the largest element in an integer array. The method should have 2 parameters as...

    • In Jgrasp(Java) Thanks! This solution must use methods. It is recommended to use methods for this...

      In Jgrasp(Java) Thanks! This solution must use methods. It is recommended to use methods for this solution. Write a program that reads an integer and displays, using asterisks, a filled and hollow square, placed next to each other. For example, if the side length is 5. the program should display: ***** ***** You can assume that the user will enter a side length that is at least 2. If user enters a number smaller than 2, and your program has...

    • Write a program that uses a recursive function to determine whether a string is a character-unit...

      Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

    • I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not...

      I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp. Here are my codes. main.cpp #include <iostream> #include <string> #include "functions.h" using namespace std; //definition of the main function. //takes arguments from the command-line. int main(int argc, char *argv[]) { //Determine if you have enough arguments. //If not, output a usage message and exit program if (argc<2 || (argc == 2 && argv[1][0] == '-')) { //call...

    • Can you help me make these two methods listed below work? I have code written but...

      Can you help me make these two methods listed below work? I have code written but it is not working. I would appreciate any advice or help. Function "isAPalidrome" accepts an array of characters and returns an integer. You must use pointer operations only, no arrays. This function should return 1 (true) if the parameter 'string' is a palindrome, or 0 (false) if 'string' is not a palindrome. A palindrome is a sequence of characters which when reversed, is the...

    • In java, please complete the methods in the class below. Add comments to identify your base...

      In java, please complete the methods in the class below. Add comments to identify your base case or base cases and the recursive steps in each of the recursive implementations. a. public String starsRecursive(int numOfLinesOfStars) takes the number of lines of stars to be in the returned string. The first line will have as many stars as numOfLinesOfStars. Each line after the first line will have one less star. The last line will have only one star. If the value...

    • Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement...

      Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement some list functionalities on an ArrrayList of generic type using type parameters in method definition Our goal for this lab is to continue using the divide and conquer approach of splitting a list into its head and tail and keep recursing on the tail (which happens to be smaller). However, instead of trying the approach on a string (a list of characters) we would...

    • ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName)...

      ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...

    • JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using...

      JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using recursion. The method signatures are included in the starter code below, with a more detailed explanation of what function the method should perform. You will be writing the following methods: stringClean() palindromeChecker() reverseString() totalWord() permutation() You will be using tools in the String class like .substring(), .charAt(), and .length() in all of these methods, so be careful with indices. If you get stuck, think...

    • Hint: User will enter certain number of random words, you need to read the input as...

      Hint: User will enter certain number of random words, you need to read the input as string and evaluate based on the following instructions. Write a void method called palindromeCheck that takes NO argument. The method should have functionality to check whether or not the word is a palindrome and print to the screen all of the palindromes, one per line. Also, the last line of the output should have the message: “There are x palindromes out of y words...

    ADVERTISEMENT
    Free Homework Help App
    Download From Google Play
    Scan Your Homework
    to Get Instant Free Answers
    Need Online Homework Help?
    Ask a Question
    Get Answers For Free
    Most questions answered within 3 hours.
    ADVERTISEMENT
    ADVERTISEMENT