Make a upside down triangle in java

To flip the triangle you really just need to change the direction of iteration. Instead of going from i = 0 to i < lines you need to go down from i = lines-1 to i >= 0

You also need to change the c to how many spaces and symbols you want to start with.

Could look like this:

int c = 2*lines;
for (int i = lines-1; i>=0; i--)
{
    for (int j = i; j < lines; j++)
    {
        System.out.print(" ");
    }
    for (int k = 1; k <= c; k++)
    {
        if (k % 2 == 0)
        {
            System.out.print(" ");
        }
        else
        {
            System.out.print(symbol);
        }
    }

    System.out.print("\n");
    c -= 2;
}

Leave a Comment