# java triangle

how is it possible to draw this type of triangle in java:

*
**
***
and

***
**
*
###### Who is Participating?

Commented:
``````		int trisize = 3;

// Draw first triangle
for (int i = 1; i <= trisize; i++) {
// Spaces infront
for(int j = 0; j < trisize - i; j++ ) {
System.out.print(" ");
}
// stars
for(int j = trisize; j > trisize - i; j-- ) {
System.out.print("*");
}
System.out.println();
}

// Draw second triangle
for (int i = trisize; i >= 1; i--) {
// Spaces infront
for(int j = 0; j < trisize - i; j++ ) {
System.out.print(" ");
}
// stars
for(int j = trisize; j > trisize - i; j-- ) {
System.out.print("*");
}
System.out.println();
}

// Draw both in one loop
for (int i = trisize; i >= -trisize; i--) {
int stars = 1 + trisize - Math.abs(i);
if (i == 0) continue; // Skip iteration

for(int j = 0; j < trisize - stars; j++ ) {
System.out.print(" ");
}
// stars
for(int j = trisize; j > trisize - stars; j-- ) {
System.out.print("*");
}
System.out.println();
}
``````
0

Commented:
What do you mean by that question?
You cat just print like that:

System.out.println("  *");
System.out.println(" **");
System.out.println("***");

or you can create a panle and draw them and fill them in.

Please, explain what do you mean by this question?

0

Commented:
0

Author Commented:
can you do these two triangles  by for loops please?

thanks,
edward
0

ArchitectCommented:
put for loop !
and use system.out.print

for each(increment) it will print one *

put if  inside the loop
system.out.println

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.