[19] diamond pattern printing program 19
Title: Print out the following pattern (diamonds)
*
***
*****
*******
*****
***
*
Analysis procedure: first to look pattern divided into two parts, the first four lines of a rule, a rule of the three lines, for using a double loop, a first control line layer, the second layer controls the column.
package cskaoyan; public class cskaoyan19 { @org.junit.Test public void rhombus() { for (int i = 0; i < 4; i++) { for (int j = 0; j <= 2 - i; j++) { System.out.print(" "); } for (int k = 0; k <= 2 * i; k++) { System.out.print("*"); } System.out.println(); } for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++) { System.out.print(" "); } for (int k = 0; k <= 4 - 2 * i; k++) { System.out.print("*"); } System.out.println(); } } }