Results 1 to 13 of 13
Thread: Hourglass using recursion
- 05-01-2012, 11:33 PM #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:
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:* * * * * * * * * * * * * * * * * * *
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.
- 05-02-2012, 01:56 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: Hourglass using recursion
Cross posted at Hourglass using recursion
- 05-02-2012, 04:15 AM #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.
- 05-02-2012, 05:30 AM #4
Re: Hourglass using recursion
One more: Hourglass Using Recursion - Java | Dream.In.Code
Cross posters don't deserve help.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-02-2012, 05:32 AM #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
- 05-02-2012, 05:33 AM #6
- 05-02-2012, 05:37 AM #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.
- 05-02-2012, 05:44 AM #8
- 05-02-2012, 05:50 AM #9
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: Hourglass using recursion
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.
- 05-02-2012, 07:07 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.
- 05-02-2012, 07:09 AM #11
Member
- Join Date
- Dec 2011
- Posts
- 14
- Rep Power
- 0
Re: Hourglass using recursion
- 05-02-2012, 07:57 AM #12
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Hourglass using recursion
- 05-02-2012, 09:11 AM #13
Similar Threads
-
Recursion.
By Cruncher in forum Advanced JavaReplies: 30Last Post: 05-10-2010, 01:06 PM -
recursion and tail-recursion differences
By OptimusPrime in forum New To JavaReplies: 2Last Post: 12-28-2009, 06:26 PM -
Need to change cursor to hourglass at server side
By bgupta in forum Java ServletReplies: 0Last Post: 02-16-2009, 07:35 AM -
Recursion
By jachandru in forum New To JavaReplies: 1Last Post: 01-24-2009, 12:52 PM -
Recursion help
By rjg_2186 in forum New To JavaReplies: 1Last Post: 01-02-2009, 08:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks