Lanqiao Cup Basic Practice Letter Graphics (Java Solution)

Problem Description

Letters can be used to form some beautiful graphics, an example is given below:

ABCDEFG

BABCDEF

CBABCDE

DCBABCD

EDCBABC

This is a graph with 5 rows and 7 columns. Please find out the pattern of this graph and output a graph with n rows and m columns.

Input format

Enter a row, which contains two integers n and m, respectively representing the number of rows and columns of the graphics you want to output.

Output format

Output n lines, each m characters, for your graphics.

Sample input

5 7

Sample output

ABCDEFG
BABCDEF
CBABCDE
DCBABCD
EDCBABC

Data scale and convention

1 <= n, m <= 26。

Find the law to achieve

import java.util.Scanner;

public class Main{
    
    
    public static void main(String[] args) {
    
    
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        for (int i = 0; i < n; i++) {
    
    
            for (int j = 0; j < m; j++) {
    
    
                System.out.print((char)('A' + Math.abs(i-j)));
            }
            System.out.println();
        }
        scanner.close();
    }
}

Guess you like

Origin blog.csdn.net/L333333333/article/details/103923459