In the practice of looping statements, it is a classic example to draw a positive triangle, but if the method is not the right one, the resulting code is very complex and not highly applied.
There are two ways to draw the positive triangle, the first is a more troublesome approach, is through the induction of each row and column and the required triangle of the intrinsic relationship obtained, more cumbersome
Package complementation;
public class Trangle {
public static void Main (string[] args) {
int row = 6;
for (int i = 1; I <= row; i++) {
int m = 1;
for (int j = 1; J <= 2 * row-1; j + +) {
if (j = = Row-i + M) {
System.out.print ("*");
M + = 2;
}
else{
System.out.print ("");
}
if (M > 2 * i-1) {
Break
}
}
System.out.println ();
}
}
The second method is to directly find the space and the number of lines given to the relationship between the asterisk and the number of rows of the link, the method is very simple, practical, should be summed up:
Package complementation;
public class Easyer {
public static void Main (string[] args) {
int row = 5;
for (int i = 0; i < row; i++) {
for (int j = 0; J < Row-i; J + +) {
System.out.print ("");
}
for (int j = 0; J <= I; j + +) {
System.out.print ("*");
}
System.out.println ();
}
}
}
A positive triangulation method in Java