In JAVA
Write a RECURSIVE method that receives as a parameter an integer named n. The method will output n # of lines of stars. For example, the first line will have one star, the second line will have two stars, and so on.
The line number n will have "n" number of ****** (stars)
so if n is 3 it would print
*
**
***
The method must not have any loops!
CODE
public class MyClass {
public static void doStarsHelper(int n, int lines, int x)
{
if(n == lines && x == lines)
return;
if(x == lines)
{
System.out.println();
doStarsHelper(n, lines+1, 0);
}
else
{
System.out.print("*");
doStarsHelper(n, lines, x+1);
}
}
public static void doStars(int n)
{
doStarsHelper(n, 1, 0);
}
public static void main(String args[]) {
doStars(5);
}
}
OUTPUT
Please up vote. I need it very badly right now. Comment if you have any doubts. Thanks!!
Get Answers For Free
Most questions answered within 1 hours.