Hi, I need help with this program here. I want to print an isosceles triangle. But, I keep ending up with this here where they are being spaced:
--------*
-------* *
------* * *
-----* * * *
----* * * * *
---* * * * * *
--* * * * * * *
-* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
Here is my code for it:
int num = 10;
int i;
int k;
int j;
for(i = 1; i <= num; i++)
{
for(k = num; k >= i; k--)
{
System.out.print(" ");
}
for(j = 1; j <= i; j++)
{
System.out.print("*");
System.out.print(" ");
}
System.out.println();
}
Even when I remove the "System.out.print(" ");" in the third for loop,
for(j = 1; j <= i; j++)
{
System.out.print("*");
System.out.print(" ");
}
it would end up like this:
--------------*
-------------**
-----------***
----------****
--------*****
------******
-----*******
---********
--*********
**********
So can anyone help me on this? Thanks.
(Note: Sorry if I didn't draw the triangles correctly. This is my first time doing this)