/**
* Output triangle
* Idea:
* 1. Use for loop nesting
* 2. External for controls the number of printed rows
* 3. The first internal space for Printing
* 4. The second for printing "*"
*/
/**
* Multiple diamond shapes are output.
* Idea:
* 1. Define the three parameters "row", "COLUN", and "M", which respectively represent the displayed number of rows, number of columns, and number of rows in the upper triangle;
* 2. Use for loop nesting
* 2. print the number of lines displayed on the outermost layer;
* 3. The second layer controls the number of rows in the upper and lower triangles of the diamond;
* 4. The third layer controls the number of columns displayed on each line.
*/
Class homework {
// Triangle
Public static void gettrangle (INT m ){
// Number of external for control rows
For (INT I = 1; I <= m; I ++ ){
// Internal for1 print space
For (Int J = 1; j <= m-I; j ++ ){
Sop ("");
}
For (Int J = 1; j <= 2 * I-1; j ++ ){
Sop ("*");
}
System. Out. println ();
}
}
Public static void commonpart (int I, int m ){
For (Int J = 1; j <= m-I; j ++ ){
Sop ("");
}
For (Int J = 1; j <= 2 * I-1; j ++ ){
Sop ("*");
}
For (Int J = m + 1; j <= 2 * m-I; j ++ ){
Sop ("");
}
}
Public static void commanpart_2 (int I, int m ){
For (Int J = 1; j <= I; j ++ ){
Sop ("");
}
For (Int J = 1; j <= 2 * (M-I) + 1; j ++ ){
Sop ("*");
}
For (Int J = 1; j <= I; j ++ ){
Sop ("");
}
}
Public static void getdown (INT num, int m ){
For (INT I = 1; I <= m; I ++ ){
For (int count = 1; count <= num; count ++ ){
Commanpart_2 (I, m );
}
Sop ("println ");
}
}
Public static void getdiamond (INT num, int m ){
For (INT I = 1; I <= m; I ++ ){
// Num indicates the number of diamond lines displayed in a row
For (int count = 1; count <= num; count ++ ){
Commonpart (I, m );
}
Sop ("println ");
}
Getdown (Num m-1 );
}
// Print the diamond
Public static void getdiamondrowcon (INT row, int COLUN, int m ){
For (INT I = 1; I <= row; I ++ ){
Getdiamond (COLUN, M );
}
}
Public static void Sop (Object O ){
If (O = "println "){
System. Out. println ();
} Else {
System. Out. Print (O );
}
}
Public static void main (string [] ARGs ){
Getdiamondrowcon (3, 3 );
}
}
I wrote this article. I hope you can give me some comments later!