How to make this triangle upside down in java?
Code :
class upsidedown {
public static void main(String args[]){
int x,y;
for (y= 1; y <= 5; y++)
{
for (x= 0; x < 5-y; x++)
System.out.print(' ');
for (x= (2-y); x < (2-y)+(2*y-1); x++)
System.out.print('*');
System.out.print('\n');
}
}
}
So far this only prints a normal triangle, how can I make it upside down?
Re: How to make this triangle upside down in java?
It would help if you provided an example of the output.
Anyway, loops generally go from 0 upwards. What happens if you start at n and go downwards?
Re: How to make this triangle upside down in java?
Re: How to make this triangle upside down in java?
My previous advice still applies. You have to work out how many spaces and stars need to printed on each line. And those values will decrease for stars and increase for spaces.
Re: How to make this triangle upside down in java?
Re: How to make this triangle upside down in java?
Go in reverse.
Start with where you stopped in the upwards one and end with where you started in the upwards one.