I am trying to make the triangle I have made up side down. Tried many times, but I don't know how to do this.
The code I have know is:
public static void drawPyramide(int lines, char symbol, boolean startDown) {
//TRIANGLE
if(startDown) {
//The triangle up side down should be here.
}
else {
int c = 1;
for (int i = 0; i < lines; 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;
}
}
}
Any suggestions how I can "flip" this triangle? Thanks.
To flip the triangle you really just need to change the direction of iteration. Instead of going from
i = 0
toi < lines
you need to go down fromi = lines-1
toi >= 0
You also need to change the
c
to how many spaces and symbols you want to start with.Could look like this:
Reverse the first loop condition i.e. start from number of line and decrease it. Also adjust you
c
accordingly and make it reduce from high to low e.g. below: