In: Computer Science
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!
public class PrintStars {
public static void main(String[] args) {
printPattern(3);
}
public static void printStars(int n) {
if (n == 0)
return;
else
System.out.print("*");
printStars(n - 1);
}
public static void printPattern(int n) {
if(n==0)
return;
else {
printPattern(n-1);
printStars(n);
System.out.println();
}
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me