Recursion help needed...
I'm trying to write a recursive program which makes a hill of astericks based on the input.
I.e. if the input was "3" the output would be something like:
*
**
***
***
**
*
So far, what I have in my code does half of it (the bottom half), but it also keeps going until it hits negative numbers so it throws the exception as well.
I'm also unsure on how to approach the top half. How do I work myself up from 1 asterick to "n" astericks without it going on for infinity. I tried doing printPattern(n+1) but that usually starts with say 3 astericks, then 4, 5, etc.
Thanks
ublicclass PatternProducer{
publicstaticvoid printRow (int stars){
if ( stars < 0)
thrownew IllegalArgumentException ("No Negative Numbers!");
if (stars < 1)
System.out.println();
else{
System.out.print("*");
printRow(stars-1);
}
}
publicstaticvoid printPattern (int n){
if ( n < 1)
System.out.println();
printRow(n);
printPattern(n-1);
}
publicstaticvoid main(String[] args){
printPattern(5);
}
}

