蓝桥杯 基础练习 字母图形

问题描述

蓝桥杯 基础练习 字母图形

Java 代码实现

import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        int m = in.nextInt();
        
        char[][] a = new char[n+5][m+5];
        char ch = 'A';
        for (int i = 0; i < m+5; ++i) {
            a[0][i] = (char)(ch+i);
        }
        for (int i = 0; i < n+5; ++i) {
            a[i][0] = (char)(ch+i);
        }
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= m; ++j) {
                a[i][j] = a[i-1][j-1];
                System.out.printf("%c", a[i][j]);
            }
            System.out.println();
        }
        
        in.close();
    }
}
上一篇:STL:标准异常类使用、编写自己的异常类


下一篇:range函数