Question: Find an example from a previous assignment where you used a loop to solve a problem. After the loop, add a call to a recursive
Find an example from a previous assignment where you used a loop to solve a problem. After the loop, add a call to a recursive method that will accomplish the same function. Keep the original loop also.
The program should show the same results with the loop as with the recursive method.
Test it to make sure it works the same as with the loop.
public class SolvingStarDesigns {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Instantiate the driver class, so you can call instance methods (& not static methods)
SolvingStarDesigns myStars = new SolvingStarDesigns();
myStars.makeDesign1();
myStars.makeDesign2();
myStars.makeDesign3();
myStars.makeDesign4();
}
/**
* Use javadoc tags to document each method:
* Using a for loop make triangle of stars - 4, 3, 2, 1 stars
* used
*/
public void makeDesign1()
{
//put your code here j
for(int i = 4;i>=1;i--)
{
for(int j = 0;j
{
System.out.print("*");
}
System.out.println();
}
System.out.println();
}
/**
* Use javadoc tags to document each method:
* using a nested for loop create right triangle of stars - 1, 2, 3. 4, & 5
*
*/
public void makeDesign2()
{
for(int i = 1;i<=5;i++)
{
for(int j = 0;j
{
System.out.print("*");
}
System.out.println();
}
System.out.println();
}
/**
* Use javadoc tags to document each method:
* using a nested for loop right triangle of stars - 5, 4, 3, 2, 1
*/
public void makeDesign3()
{
for(int i = 5;i>=1;i--)
{
for(int j = 0;j
{
System.out.print("*");
}
System.out.println();
}
System.out.println();
}
/**
* Use javadoc tags to document each method:
* using a nested for loop made a Outcome right triangle of stars - 1, 3, 5, 7 stars
*/
public void makeDesign4()
{
for(int i = 1;i<=7;i+=2)
{
for(int j = 0;j
{
System.out.print("*");
}
System.out.println();
}
System.out.println();
}
}
i need help turning these for loops into a recursive method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
