解题思路:
注意事项:
参考代码:
package cWeb.buleCup; import java.util.Scanner; public class C1115 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int N = in.nextInt(); while(N!=0) { int a = in.nextInt(); int b = in.nextInt(); for (int i = 1; i <= (a+1)/2; i++) { //打印前面空格 for (int j = 1; j <= i-1; j++) { System.out.print(" "); } if(i!=((a+1)/2)) { System.out.print("X"); for (int j = 1; j <=-2*(i-1)+a-2; j++) { System.out.print(" "); } System.out.print("X"); System.out.println(); }else { System.out.print("X"); System.out.println(); } } for (int i = 1; i <=a-((a+1)/2); i++) { for (int j = 1; j <= a-((a+1)/2)-i; j++) { System.out.print(" "); } System.out.print("X"); for (int j = 1; j <=2*i-1 ; j++) { System.out.print(" "); } System.out.print("X"); System.out.println(); } while((b-1)!=0) { for (int i = 2; i <= (a+1)/2; i++) { //打印前面空格 for (int j = 1; j <= i-1; j++) { System.out.print(" "); } if(i!=((a+1)/2)) { System.out.print("X"); for (int j = 1; j <=-2*(i-1)+a-2; j++) { System.out.print(" "); } System.out.print("X"); System.out.println(); }else { System.out.print("X"); System.out.println(); } } for (int i = 1; i <=a-((a+1)/2); i++) { for (int j = 1; j <= a-((a+1)/2)-i; j++) { System.out.print(" "); } System.out.print("X"); for (int j = 1; j <=2*i-1 ; j++) { System.out.print(" "); } System.out.print("X"); System.out.println(); } b--; } System.out.println(); N--; } } }
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:690 |
C语言程序设计教程(第三版)课后习题9.3 (Java代码)浏览:1025 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:701 |
1009题解浏览:802 |
Hello, world! (C语言代码)浏览:766 |
DNA (C语言代码)浏览:440 |
DNA (C语言代码)浏览:798 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:650 |
淘淘的名单 (C语言代码)浏览:1309 |
1073题解浏览:652 |