Print a diamond in the Java Console

Source: Internet
Author: User

 

/***//**
* Fig. Java
* Print a diamond in the Java Console
* @ Author Deng Chao (codingmouse)
* @ Version 0.1
* Development/test environment: jdk1.6 + eclipse SDK 3.3.2
*/

// Import the category class
Import java. util. collections;

Public class fig ...{
 
Public static void main (string [] ARGs )...{

Wrote input = new partition (system. In );

// Loop ID
Boolean con = true;
// Number of diamond layers and number of layers after Conversion Calculation
Int border, num = 0;

Do ...{
Con = false;
System. Out. Print ("Enter the number of diamond layers to print [no less than 3 odd (integer)]:");
// Diamond Layers
Border = input. nextint ();

If (border % 2 = 0 | border <3 )...{
System. Out. println ("can only enter the odd (integer) number not less than 3! Please try again! ");
Con = true;
}
} While (CON );

// Number of layers to be converted
Num = border-(border % 2)/2;

// Console output prompt
System. Out. println (border + "layer diamond pattern :");

// Print the upper part of the image
For (INT I = 1; I <= num; I ++ )...{

For (Int J = 1; j <= num-I; j ++ )...{
// System. Out. Print (""); // This is a little longer
System. Out. Print ("");
}

For (Int J = 1; j <= 2 * (I + 1)-3; j ++ )...{
// System. Out. Print ("*"); // a little longer
System. Out. Print ("*");
}

System. Out. println ();
}

// Print the lower half Image
For (INT I = 1; I <= num-1; I ++ )...{

For (Int J = 1; j <= I; j ++ )...{
// System. Out. Print (""); // This is a little longer
System. Out. Print ("");
}

Int K = num-1-I;

For (Int J = 1; j <= 2 * k + 1; j ++ )...{
// System. Out. Print ("*"); // a little longer
System. Out. Print ("*");
}

System. Out. println ();
}
}
}

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.