字母图形 2021.12.06

package introductory;
/*
    7 5
ABCDE
BABCD
CBABC
DCBAB
EDCBA
FEDCB
GFEDC
 */
import java.util.Scanner;

public class test13 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        String[][] a = new String[n][m];
        String[] strings = {
                "A","B","C","D","E","F","G","H","I","J","k","L","M",
                "N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
        };

        for(int i=0; i<m; i++){
            a[0][i] = strings[i];
        }

        for(int i=0; i<n; i++){
            a[i][0] = strings[i];
        }

        for(int i=1; i<n; i++){
            for(int j=1; j<m; j++){
                if( j >= i ){
                    a[i][j] = a[i-1][j-1];
                }else{
                    a[i][j] = a[j%n][i%m];
                }
            }
        }

        //输出
        for(int i=0; i<n; i++){
            for(int j=0; j<m-1; j++){
                System.out.print(a[i][j]);
            }
            System.out.println(a[i][m-1]);
        }

//                Scanner input = new Scanner(System.in);
//                int n = input.nextInt();
//                int m = input.nextInt();
//                for(int i = 0;i < n;i++){
//                    for(int j = 0;j < m;j++ ) {
//                        char s = (char)(Math.abs(i - j) + 'A');
//                        System.out.print(s);
//                    }
//                    System.out.print("\n");
//
//                }
    }
}

上一篇:06 _ 数据同步:主从库如何实现数据一致?


下一篇:2021/12/06