董丕通


私信TA

用户名:dotcpp0726583

访问量:415

签 名:

等  级
排  名 1123
经  验 3119
参赛次数 4
文章发表 15
年  龄 0
在职情况 学生
学  校 淄博职业学院
专  业

  自我简介:

TA的其他文章


解题思路:

注意事项:

参考代码:

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i=1; i<=n ;i++) { // 存在N组数据
            int a = scan.nextInt(); // 行数
            int b = scan.nextInt(); // 重复次数
            for(int k=1; k<=b; k++) { //图形重复次数
                for(int h=0; h<a; h++) {
                    if( k != 1 && h == 0) continue; //除了第一次图形就不需要打印第一行了
                    for(int l=0; l<a; l++) 
                        if( l==h || l + h == a-1 ) System.out.print('X');
                        else System.out.print(' ');
                    System.out.println();
                }
            }
            System.out.println();
        }
    }
}


 

0.0分

1 人评分

  评论区