空心菱形
- package com.tjau_03_ForFor;
- import java.util.Scanner;
- public class KongXinLingXing {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入菱形边长:");
- int num = sc.nextInt();
- for (int i = 1; i <= num; i++) {
- for (int j = 1; j < num - i + 1; j++) {
- System.out.print(" ");
- }
- int count = 2 * i - 1;
- for (int k = 1; k<=count; k++) {
- if (1 == k || count == k)
- System.out.print("*");
- else
- System.out.print(" ");
- }
- System.out.println("");
- }
- for (int i = 1; i < num; i++) {
- for (int j = 1; j <= i; j++) {
- System.out.print(" ");
- }
- int count = 2 * (num - i) - 1;
- for (int k = 1; k <= count; k++) {
- if (k == 1 || k == count)
- System.out.print("*");
- else
- System.out.print(" ");
- }
- System.out.println("");
- }
- }
- }
复制代码 |
|