Java ASCII recursion Art

Program which create vertical pyramid with recursion

public class MainClassVisualRecursionV {
    public static void main(String[] args) {
        recursion(5, "", "\\", "/");
    }

    public static int recursion(int deep, String space, String symbol, String flipSymbol)
    {
        System.out.println(space + symbol);
        if(deep < 0)
        {
            System.out.println(space + flipSymbol);
        }
        else
        {
            recursion(deep - 1, space + "  ", symbol, flipSymbol);
            System.out.println(space + flipSymbol);
        }
        return deep;
    }
}

Output:

\
  \
    \
      \
        \
          \
            \
            /
          /
        /
      /
    /
  /
/

Leave a Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.