09-使用for循环输出空心菱形(循环)

/**
 * 使用for循环输出空心菱形
 * 
 */
public class Test7 {
	public static void main(String[] args) {
		for (int i = 1; i <= 5; i++) {
			for (int j = 1; j < 11 - 2 * i; j++) {
				System.out.print(" ");
			}
			for (int k = 1; k <= 2 * i - 1; k++) {
				if (k == 1 || k == 2 * i - 1) {
					System.out.print("*");
				} else {
					System.out.print("  ");
				}

			}
			System.out.println();
		}
		for (int i = 4; i >= 1; i--) {
			for (int j = 9; j > 2 * i - 1; j--) {
				System.out.print(" ");
			}
			for (int k = 1; k <= 2 * i - 1; k++) {
				if (k == 1 || k == 2 * i - 1) {
					System.out.print("*");
				} else {
					System.out.print("  ");
				}
			}
			System.out.println();
		}

	}
}

09-使用for循环输出空心菱形(循环)_第1张图片

你可能感兴趣的:(for循环)