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();
		}

	}
}


posted @ 2013-06-20 18:47  jlins  阅读(730)  评论(0编辑  收藏  举报