JAVA如何用字母表示等腰三角形

输出c,用等腰三角表示出来

img

类同a
bab
cbabc的形式,如何输出

public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            for (int j = 4; j > i; j--) {
                System.out.print(" ");
            }
            for (int j = i; j >= 0; j--) {
                 System.out.print((char)('a'+j));
            }
            for (int z = 0; z < i; z++) {
                System.out.print((char)('a'+z+1));
            }
            System.out.println();
        }
    }
        int n = 5; // 行数
        for (int i = 0; i < n; i++) {
            for (int j = n - 1; j > i; j--) System.out.print(" ");
            for (int j = i; j >= 0; j--) System.out.print(((char) ('a' + j)));
            for (int j = 0; j < i; j++) System.out.print(((char) ('b' + j)));
            System.out.println();
        }

public class Test {

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("请输入英文字母:");
    // 读取输入的字符串
    String name = input.next();
    char word = name.charAt(0);
    //先判断输入的是否是字母
    if(Character.isLetter(word)){
        if(name.length() == 1){
            // 检查字母是否为小写字母
            boolean checkData = checkIsLowerCase(name);
            if (!checkData) {
                //不是小写,将大写转成小写
                word = toLowerCase(name.charAt(0));
            }
            //获取字母位置
            int index = (int)word-96;
            //执行输出等腰三角形操作
            System.out.println("输出结果为:");
            doDataResult(index);
        }else {
            System.out.println("您输入的字符不合法!");
        }
    }else {
        System.out.println("请输入字母!");
    }
}

/**
 * 执行输出操作
 * @param index
 */
private static void doDataResult(int index) {
    for (int i = 0; i < index; i++) {
        for (int j = index-1; j > i; j--) {
            System.out.print(" ");
        }
        for (int j = i; j >= 0; j--) {
            System.out.print((char) ('a' + j));
        }
        for (int z = 0; z < i; z++) {
            System.out.print((char) ('a' + z + 1));
        }
        System.out.println();
    }
}

/**
 * 检查字母是否为小写字母
 * @return
 */
private static boolean checkIsLowerCase(String word) {
    boolean b=true;
    for(int i = 0; i < word.length(); i++)
    {
        char c = word.charAt(i);
        if (!Character.isLowerCase(c))
        {
            b= false;
        }
    }
    return b;
}


/**
 * 大写字母转成小写
 * @param c1
 * @return
 */
public static char toLowerCase(char c1) {
    int a = (int) c1;
    int b = a + 32;
    char bb = (char) b;
    return bb;
}

}