Java console Super Diamond printing method

Source: Internet
Author: User

Source code list:

/***//**
* Supperrhombus. Java
* Super Diamond printing method on the Java Console
* @ Author Deng Chao (codingmouse)
* @ Version 0.1
* Development/test environment: jdk1.6 + eclipse SDK 3.3.2
*/

// Import the watermark class and printstream class
Import java. util. collections;
Import java. Io. printstream;

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

Wrote input = new partition (system. In );

// Loop ID
Boolean con = true;
// Number of diamond rows
Int line;

Do ...{
Con = false;
System. Out. Print ("Enter the number of diamond layers to print [no less than 3 odd (integer)]:");
// Obtain the number of diamond lines entered by the console user
Line = input. nextint ();

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

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

// Because the number of lines in the diamond cannot be an even number, it must be converted to an odd number.
Line = (line & 1) = 0? Line + 1: line;
 
Printstream out = system. out;

For (INT I = 0-line/2; I <= line/2; I ++ )...{
For (Int J = 0-line/2; j <= line/2; j ++ )...{
// Change = to <= or> = to generate the image
// Out. Print (math. Abs (I) + math. Abs (j) = line/2 )? "*": ""); // Hollow Diamond
// Out. Print (math. Abs (I) + math. Abs (j) <= line/2 )? "*": ""); // Solid diamond
Out. Print (math. Abs (I) + math. Abs (j)> = line/2 )? "*": ""); // Embedded Diamond
}
Out. println ();
}
}
}

Execution result:

Enter the number of diamond layers to print [no less than 3 odd (integer)]: 11
The layer-11 diamond pattern is as follows:
* * * * * * * * * * * 
* * * * *   * * * * *
* * * *       * * * *
* * *           * * *
* *               * *
*                   *
* *               * *
* * *           * * *
* * * *       * * * *
* * * * *   * * * * *
* * * * * * * * * * *

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.