Output multiple diamond maps and write them again!

Source: Internet
Author: User

/**
* 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.