Consider the problem of displaying a pattern of asterisks which form a triangle of height h, as shown below for h = 4: *
**
***
****
***
**
*
The problem can be solved with the recursive helper method shape below. The method takes two parameters: low and high. It first prints a row of asterisks corresponding to parameter low. If high is higher than low, it recursively generates a shape in which low is incremented by one, and then prints another row of low asterisks. Select a statement to complete method triangle, so that the helper method shape is invoked with the correct arguments in order to display a triangle with parameter height.
Public static void shape(int low, int high)
{
If (high >= low)
{
AsterisksRow(low) ;
If (high > low)
{
Shape(low + 1, high) ;
AsterisksRow(low) ;
}
}
}
Public static void asterisksRow(int n) // Method to display a row of n stars
{
For (int j = 1; j < n; ++j)
{
System.out.print("*") ;
}
System.out.println("*") ;
}
Public static void triangle(int height)
{
If (height > 1)
{
_______________________
}
}
A) shape(0, height) ;
B) shape(0, height - 1) ;
C) shape(1, height) ;
D) shape(0. height - 1) ;
Correct Answer:
Verified
Q59: Complete the code for the calcPower recursive
Q60: Complete the following code snippet, which is
Q61: Consider the recursive square method shown below
Q62: Consider the helper method reversePrint, which uses
Q63: Complete the following code snippet, which is
Q65: Complete the following code snippet, which is
Q66: A palindrome is a word or phrase
Q67: Consider the fib method from the textbook
Q68: Assume that recursive method search returns true
Q69: What is the purpose of a recursive
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents