Home > Back-end >  Double for loop output various shapes of triangle
Double for loop output various shapes of triangle

Time:01-30

 public class TwoFor {
Public static void main (String [] args) {
//right triangle array
/* for (int I=0; I<5; I++) {
For (int k=4; K> i; K -) {
System. The out. Print (" ");
}
for(int j=0; J<=I; J++) {
System. The out. Print (" * ");
}
System.out.println();
} */
//congruent triangles
/* for (int I=0; I<5; I++) {
For (int k=4; K>=I; K -) {
System. The out. Print (" ");
}
for(int j=0; J<=I; J++) {
System. The out. Print (" * ");
}
System.out.println();
} */

//left right triangle
/* for (int I=0; I<5; I++) {
for(int j=0; J<=I; J++) {
System. The out. Print (" * ");
}
System.out.println();
} */

//to the right triangle
/* for (int I=0; I<5; I++) {
For (int k=0; k<=I; K++) {
System. The out. Print (" ");
}
For (int j=4; J>=I; J -) {
System. The out. Print (" * ");
}
System. The out. Println (" ");
} */
}
}

Right right triangle:

Congruent triangles:

Left right triangle:

Pour a right triangle:

CodePudding user response:

Suggest do the building Lord Yang hui triangle problem, a very classic topic! I am also beginners

CodePudding user response:

Behind the back post two years ago, for beginners to see!!!!!!!!!!!
The last "nabla" can do not need to print out the blank space, because you this is the left right triangle
If you want to print out the right right triangle, still need to print out the inverted 5 diminishing line by line "blank space"
  • Related