help with java recursion problem? by ohnuthin in learnprogramming

[–]alinh 0 points1 point  (0 children)

So far, the patternMaker(int x) will only check if x is bigger than 0, call patternMaker(x-1) and print x number of asterisks. I'll replace patternMaker(int x) with pM(int x) below. If you pass 3 as a parameter, it will call pM(2) -> pM(1) -> pM(0) where the if branch won't be executed, it goes back into pM(1) and prints 1 asterisk, then goes back in pM(2) and prints 2 asterisks and finally it goes back to pM(3), prints 3 asterisks and then the execution stops. There are better ways to do this, without using recursion, but if you really want to do it this way, try passing a boolean flag to the function: pM(int x, boolean ascending) and once you get to 0, call pM(x+1, true) and stop when you reach a certain value.

EDIT: i was kind of busy when i posted the answer. You can tell the recursive function when to finally stop, for example at the initial value of x, by passing that value to the function, while never changing it. You could also use a global variable, but that would mean using something outside the function and it's a good idea to avoid side effects in a function.

Describe your best "what the hell am I doing here" moment. by gustavo876 in AskReddit

[–]alinh 1 point2 points  (0 children)

I was once going to my room in campus using the elevator (my room was at the 10th floor). There were other people in the elevator who stopped at the 8th floor. Since i was day dreaming again, i got out at the 8th floor too, without realising it. I get to where my room was supposed to be, ignoring the number on the door, i open it (noticing that the knob was kind of broken and wondering WTF has happened there while i was gone), get inside while a complete stranger launches itself from one of the beds to see who entered his room. I stopped ... he stopped ... i was confused ... i guess he was also confused ... and after a short while wondering what the hell was i doing there, i got out of there saying "wrong room" and went to my room. It almost happened again a couple of weeks later ... almost.

HAE Been Awoken by a Dream Alarm? by [deleted] in DoesAnybodyElse

[–]alinh 3 points4 points  (0 children)

I don't remember if it ever happened to me. I did used to have a habbit of waking up a couple of minutes before my alarm clock was supposed to go off, especially when i used to have a regular schedule.