Question
Write a recursive method with the following specification and header: // Parameters: m - number of asterisks in the first line // n - number
Write a recursive method with the following specification and header:
// Parameters: m - number of asterisks in the first line // n - number of asterisks in the middle 2 lines // Precondition: m <= n, m > 0, n > 0
// Postcondition: The method has printed a pattern of 2*(n-m+1) lines
// to the standard output. The first line contains m asterisks, the next
// line contains m+1 asterisks, and so on up to a line with n asterisks.
// Then the pattern is repeated backwards, going n back down to m. /* Example output:
triangle(3, 5) will print this: *** **** *****
***** **** ***
*/ public static void triangle(int m, int n)
Hint: Only one of the arguments changes in the recursive call. Which one?
***For this method, write a program that would test it. The program should prompt the user to enter value(s) of parameter(s) and execute the method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started