@java Blue Bridge Cup Group B Exercise Basics (30) Third question: graphics letters
Keywords: loop, string
Problem Description
Use of the letters can form some beautiful graphics, an example is given below:
ABCDEFG
BABCDEF
CBABCDE
DCBABCD
EDCBABC
This is a pattern row 5 7, find the pattern of this rule, and outputs a pattern of n rows and m columns.
Input format
input line, comprising two integers n and m, respectively represent the number of columns you want output line pattern.
Output format
output n lines, each m characters, for your pattern.
Input Sample
57
Sample Output
ABCDEFG
BABCDEF
CBABCDE
DCBABCD
EDCBABC
data size and Conventions
1 <= n, m <= 26.
Code:
public class Main {
public static void main(String[] args) {
java.util.Scanner s=new java.util.Scanner(System.in);
int n=s.nextInt();
int m=s.nextInt();
char str;
char[][] shu=new char[26][26];
for(int i=0;i<n;i++){
str='A';
for(int j=i;j<m;j++){
shu[i][j]=str++;
}
str='A';
for(int j=i-1;j>=0;j--){
shu[i][j]=++str;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(shu[i][j]);
}
System.out.println();
}
}
}