参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); for (int i = 0; i < n; i++) { int a=scanner.nextInt(); int b=scanner.nextInt(); char[][] num=new char[a][a]; for (int j = 0; j < num.length; j++) { for (int j2 = 0; j2 < num[j].length; j2++) { num[j][j2]=' '; } } for (int j = 0; j < num.length; j++) { num[j][0+j]='X'; num[j][num[j].length-1-j]='X'; } for(int t=0;t<b;t++){ if (t>0) { for (int j = 1; j < num.length; j++) { for (int j2 = 0; j2 < num[j].length; j2++) { System.out.print(num[j][j2]); } System.out.println(); } }else { for (int j = 0; j < num.length; j++) { for (int j2 = 0; j2 < num[j].length; j2++) { System.out.print(num[j][j2]); } System.out.println(); } } } System.out.println(); } } }
0.0分
1 人评分
C二级辅导-同因查找 (C语言代码)浏览:590 |
不知道哪里错了浏览:1226 |
大神老白 (C语言代码)浏览:768 |
C语言训练-角谷猜想 (C++代码)(3N+1问题)浏览:1850 |
川哥的吩咐 (C++代码)浏览:1076 |
C语言训练-最大数问题 (C语言代码)浏览:648 |
矩阵乘法 (C++代码)浏览:1662 |
大小写转换 (C语言代码)浏览:904 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1261 |
剪刀石头布 (C语言代码)浏览:1792 |