输出语句问题- public class Demo {
- public static void main(String[] args) {
- int num = 23;
- int height = num/4+1;
- int width = num;
-
- int[][] arr = new int[height][width];
- int x = height-1;
- int y = 0;
- boolean count = true;
- for(int i=1; i<=width; i++){
- arr[x][y] = i;
- y++;
- if(count){
- x--;
- }else{
- x++;
- }
- if(x<0){
- x=x+2;
- count = false;
- }
- if(x>height-1){
- x=x-2;
- count = true;
- }
- }
-
- for(int i=0; i<arr.length; i++){
- for(int j=0; j<arr[i].length; j++){
- if(arr[i][j]==0){
- System.out.print(" ");//输出语句上的问题
- }else{
- System.out.print(arr[i][j]);
- }
- }
- System.out.println();
- }
- }
-
- }
复制代码 |
|