輸入數字輸出相對應方塊陣列

1,2,3,4,5,6          1,2,3
1,2,3,4,5,5          1,2,2
1,2,3,4,4,4          1,1,1
1,2,3,3,3,3
1,2,2,2,2,2
1,1,1,1,1,1

 

 

package ch7;
import java.io.*;
public class ch7_14_2 {
    public static void main(String awgs[])throws IOException
    {
        InputStreamReader in=new InputStreamReader(System.in);
        BufferedReader buf=new BufferedReader(in);
        int x,a,b,c;
        String sx;
        sx=buf.readLine();
        x=Integer.parseInt(sx);
        int num[][]=new int [x][x];
        int onum[][]=new int [x][x];
        for(a=0;a<x;a++)
            {
            for(b=0;b<x;b++)
            {
                if(a<=b)
                {
                    c=a;
                }else
                {
                    c=b;
                }
                num[a][b]=c+1;
            }
        }
        for(a=0;a<x;a++)
        {
            for(b=0;b<x;b++)
            {
                onum[x-a-1][b]=num[a][b];
            }
        }
        for(a=0;a<x;a++)
        {
            for(b=0;b<x;b++)
            {
                System.out.print((onum[a][b])+",");
            }
            System.out.println();
        }
    }

}
================

6
1,2,3,4,5,6,
1,2,3,4,5,5,
1,2,3,4,4,4,
1,2,3,3,3,3,
1,2,2,2,2,2,
1,1,1,1,1,1,
 

創作者介紹
創作者 驢子的生活日記 的頭像
驢子

驢子的生活日記

驢子 發表在 痞客邦 留言(0) 人氣( 20 )