# Thread: Hourglass using recursion

1. Member
Join Date
Dec 2011
Posts
14
Rep Power
0

## Hourglass using recursion

I have to write a recursive program that makes an hourglass that suites the size of the user's input. For example, if the user types 4, this should print:

Java Code:
```* * * *
* * *
* *
*
* *
* * *
* * * *```
and so far I got this far:

Java Code:
```* * * *
* * *
* *
*
* *
* * *
* * * *```
so I just need to figure out how to get the spaces but I'm not sure how to do this. Thanks for the help.

Java Code:
```import java.util.InputMismatchException;
import java.util.Scanner;

public class Hourglass {

public static void main(String[] args) {

Scanner console = new Scanner(System.in);
System.out.println("Enter an integer greater than or equal to 1");
int n = 0;
try {
n = console.nextInt();
} catch (InputMismatchException e) {
e.getMessage();
}
if (n < 1) {
System.out.println("Invalid input");
} else {
System.out.println("");
hourglass(n, 0);
System.out.println("");
}

}

public static void hourglass(int n, int count) {
recursion(n, count);
if(n > 1) {
hourglass(n-1, count);
recursion(n, count);
}
}

public static void recursion(int n, int count) {
System.out.print("* ");
if (n > 1)
recursion(n - 1, count);
else
System.out.println();
}
}```
Last edited by nweid1; 05-01-2012 at 11:41 PM.

2. Moderator
Join Date
Jul 2010
Location
California
Posts
1,638
Rep Power
12

## Re: Hourglass using recursion

Cross posted at Hourglass using recursion

3. Member
Join Date
Dec 2011
Posts
14
Rep Power
0

## Re: Hourglass using recursion

Hey, thanks for wasting your time and my time by posting "cross posted" but not helping with either of the posts.

4. ## Re: Hourglass using recursion

One more: Hourglass Using Recursion - Java | Dream.In.Code

Cross posters don't deserve help.

db

5. Member
Join Date
Dec 2011
Posts
14
Rep Power
0

## Re: Hourglass using recursion

Cross posters don't deserve help? What are you, 5 years old? Grow up and find something better to do than patrolling programming forums lol

6. ## Re: Hourglass using recursion

Originally Posted by nweid1
Cross posters don't deserve help? What are you, 5 years old? Grow up and find something better to do than patrolling programming forums lol
Ah, the misbegotten sense of entitlement of the least worthy!

/yawns

db

7. Member
Join Date
Dec 2011
Posts
14
Rep Power
0

## Re: Hourglass using recursion

/yawns? Come on man you must still be living in your mom's basement. I'm still confused as to why you're on this post if you're just going to act like a kid.

8. ## Re: Hourglass using recursion

Originally Posted by nweid1
/yawns? Come on man you must still be living in your mom's basement. I'm still confused as to why you're on this post if you're just going to act like a kid.
Carry on wasting time antagonizing the very people who might have helped you, all the way to your failed grade.

db

9. Moderator
Join Date
Jul 2010
Location
California
Posts
1,638
Rep Power
12

## Re: Hourglass using recursion

Originally Posted by nweid1
Hey, thanks for wasting your time and my time by posting "cross posted" but not helping with either of the posts.
I do recommend you read the links provided to you on other forums, in particular the following:
The problems with cross-posting
We do feel like our time is wasted, not for posting crosspost notices, but for replying to a post that has been answered and/or discussed elsewhere that is not disclosed.

Cross posting is not against forum rules, but it has to do with respect. Presuming you are a reasonable person: you ask for help from unpaid volunteers - you should respect those that are trying to help. Otherwise, we all loose respect for you and your chances of receiving help - here or elsewhere now and in the future, go to 0.
Last edited by doWhile; 05-02-2012 at 05:54 AM.

10. Member
Join Date
Dec 2011
Posts
14
Rep Power
0

## Re: Hourglass using recursion

The fact that you are limiting another person's knowledge on a subject because of the crime of cross-posting just makes you out to be a...jerk. Sorry if "jerk" seems kiddish but I wouldn't want to get reported to the programming police for saying something vulgar.

11. Member
Join Date
Dec 2011
Posts
14
Rep Power
0

## Re: Hourglass using recursion

Originally Posted by doWhile
I do recommend you read the links provided to you on other forums, in particular the following:
The problems with cross-posting
We do feel like our time is wasted, not for posting crosspost notices, but for replying to a post that has been answered and/or discussed elsewhere that is not disclosed.

Cross posting is not against forum rules, but it has to do with respect. Presuming you are a reasonable person: you ask for help from unpaid volunteers - you should respect those that are trying to help. Otherwise, we all loose respect for you and your chances of receiving help - here or elsewhere now and in the future, go to 0.
Advice taken. From now on I'll take note to it but seeing as though I rarely use this forum I didn't know it was such a huge deal to widen my range of advisers. But I must say though that yet again I have a comment and yet no help. Thank you.

12. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

13. ## Re: Hourglass using recursion

Originally Posted by pbrockway2
Thanks, I've looked after those two and I'm keeping an eye on two other forums that haven't so far figured in the list.

db

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•