输出三角形字符金字塔 Java语言版

别骂了 别骂了

测试


package org.example;

/**
 * @Classname Demo
 * @Description TODO
 * @Date 2020/7/17 15:12
 * @Author qiu
 */
public class Demo {
    public static void main(String[] args) {
        int n = 'E' - 'A' + 1;//上半部分
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                System.out.print(" ");
            }
            for (int j = 0; j <= i; j++) {
                char temp = (char) ('A' + j);
                System.out.print(temp);
            }
            for (int j = i - 1; j >= 0; j--) {
                char temp = (char) ('A' + j);
                System.out.print(temp);
            }
            System.out.println();
        }  //下半部分
        for (int i = n-1; i >= 0; i--) {
            for (int j = n - i - 1; j >= 0; j--) {
                System.out.print(" ");
            }
            for (int j = 0; j <= i-1; j++) {
                char temp = (char) ('A' + j);
                System.out.print(temp);
            }
            for (int j = i - 2; j >= 0; j--) {
                char temp = (char) ('A' + j);
                System.out.print(temp);
            }
            System.out.println();
        }
    }
}

你可能感兴趣的:(输出三角形字符金字塔 Java语言版)