關於部落格
Android‧教學分享‧娛樂共享
  • 67902

    累積人氣

  • 0

    今日人氣

    0

    追蹤人氣

用*顯示倒V

import java.util.Scanner;

public class DemoV {

    public static void main(String[] argv) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("請輸入數字:");
        int num = scanner.nextInt();
        for (int i = 0; i < = num - 1; i++) {
            for (int j = num + 1; j >= i; j--) {
                if (j == i) {
                    System.out.print("*");
                    for (int k = 0; k <= i * 2 - 1; k++) {
                        if (k == i * 2 - 1) {
                            System.out.print("*");
                        } else {
                            System.out.print(" ");
                        }
                    }
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println(" ");
        }
    }
}

相簿設定
標籤設定
相簿狀態