Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:24:25+00:00 2026-06-08T16:24:25+00:00

i am working on what should be a relatively simple java recursion problem, though

  • 0

i am working on what should be a relatively simple java recursion problem, though i cannot seem to find a straightforward, one-method solution anywhere.

i am trying to print out asterisks in descending followed by ascending order, so that when the user passes in 3 for example, the print out will look like this:

*
**
***
**
*

EDIT: thanks to the help of @dasblinkenlight this has evolved to:

public void patternMaker(int start, int max, int direction){
    if(start == 0){
        return;
    }
    for(int i = 0; i < start; i++){
        System.out.print("*");
    }
    System.out.println();
    if(start == max){
        direction = -1;
    }
    patternMaker(start + direction, max, direction);

NOW, it prints the correct amount of asterisks, AND in the proper order:

*
**
***
**
*

thanks everyone for helping!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:24:27+00:00Added an answer on June 8, 2026 at 4:24 pm

    You need another parameter to tell you which way you are going. You also need to test for the end condition to know when to switch from going up to going down.

    public void patternMaker(int x, int direction){
        // Direction is either +1 or -1, depending on whether you go up or down
        // at the moment. Once you reach 3, switch the sign;
        // Once you reach zero, stop.
    
        // Pseudocode:
        // If x is zero, we're done
        // Print x asterisks followed by newline
        // if x == 3, make direction -1
        // Perform the recursive call with (x+direction, direction)
    }
    

    It would probably be easier to draw stars before recursing down, although both ways are certainly possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tough problem where I'm desperately trying to find a working solution.
I've got a strange problem in that my function is working as it should
This should be totally simple but I can't get it working no matter what
I'm working on a Java program that should repeatedly kill two processes as soon
The app I'm working on is relatively simple but it is throwing memory warnings.
This should be pretty simple but it's not working. I have a file underneath
I'm still relatively new to Java. I've tried searching for a solution, but I
I'm working on this relatively simple site: http://harrisonfjord.com/folio/test.html The images being displayed are 800x600;
I am working on a relatively simple, independent process starter that I would like
http://jsfiddle.net/nicktheandroid/k93ZK/2/ This should be really simple, I just don't understand why it's not working.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.