Hollow Letter Pyramid (Java)

Enter an uppercase English letter and output a hollow letter pyramid.

Input format:
one uppercase English letter.

Output format:
A hollow capital English letter pyramid, where the "A" in the first layer is in the 40th column of the first row, and the column starts counting from 1.

Input example: E

Sample output:
Insert picture description here

import java.util.Scanner;

public class Main {
    
    
    public static void main(String[] args) {
    
    
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        Main.print(s);

    }
    public static void print(String s){
    
    
        for (int i=65;i<=s.charAt(0);i++){
    
    
            for (int j=1;j<105-i;j++){
    
    
                System.out.print(" ");
            }
            System.out.print((char)i);
            if (i!=65&&i<s.charAt(0)){
    
    
                for (int k = 0; k < i-65; k++) {
    
    
                    System.out.print(" ");
                }
                for (int l = 0; l < i-66; l++) {
    
    
                    System.out.print(" ");
                }
            }
            if (i==s.charAt(0)){
    
    
                for (int m=1;m<2*(i-65);m++){
    
    
                    System.out.print((char)i);
                }
            }
            if (i!=65) System.out.print((char)i);
            System.out.println();
        }
    }
}

Guess you like

Origin blog.csdn.net/weixin_51430516/article/details/115048485