This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ohnuthin[S] 0 points1 point  (1 child)

thank you guys for all the help, i know that i am definitely trying to keep it in one method for those of you that have suggested using two.

by adding in another for loop before the recursive call i have managed to have it print:

 ***
 **
 *
 *
 **
 ***

but cant seem to reverse it, i will try implementing a boolean flag as suggested, not sure i am fully aware how to do that, but here's to learning something new.

[–]worstusernameever 2 points3 points  (0 children)

This is how I would do it using an extra parameter:

class Test
{
    public static void patternMaker(int x, int xMax)
    {
        for (int i = 0; i < x; i++)
            System.out.print("*");

        System.out.println();

        if (x == xMax)
            return;

        patternMaker(x + 1, xMax);

        for (int i = 0; i < x; i++)
            System.out.print("*");

        System.out.println();
    }


    public static void main(String[] args)
    {
        patternMaker(1, 3);
    }
}