解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); while (n > 0) { n--; int a = sc.nextInt(); int b = sc.nextInt(); String[][] arr = new String[a][a]; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr.length; j++) { arr[i][j] = " "; } } int c = 0; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr.length; j++) { arr[c][i] = "X"; arr[arr.length - 1 - c][i] = "X"; } c++; } for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr.length; j++) { System.out.print(arr[i][j]); } System.out.println(); } b = b-1; while (b!=0) { for (int i = 1; i < arr.length; i++) { for (int j = 0; j < arr.length; j++) { System.out.print(arr[i][j]); } System.out.println(); } b--; } System.out.println(); } } }
0.0分
2 人评分