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:
* * * * * * * * * * *
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *