자바로 이 알고리즘을 짜봤습니다.



소스코드.


public class Fifteen2 {

    public static void main(String args[])
    {
        int A[][] = new int[8][8];
        int Q =0;
        
        int SMALL = 1;
        int LARGE = 7;
        int C = (7/2)+1;
        
        //만들기
        for(int i=1; i<=7; i++)
        {
            Q = SMALL;
            
            for(int j =SMALL; j<=LARGE; j++)
            {
                A[i][j] = Q;
                Q++;
    
            }            
                if(i<C)
                {
                    SMALL = SMALL + 1;
                    LARGE = LARGE - 1;
                }
                else
                {
                    SMALL = SMALL - 1;
                    LARGE = LARGE + 1;
                }
        }//for
        
        //출력~!~!
        for(int i = 1; i<=7; i++)
        {
            for(int j = 1; j<=7; j++)
            {
                
                System.out.print(A[i][j] + "  ");
                if(j==7)
                {
                    System.out.println("");
                }
            }
        }
        
    }
}



출력화면



 


+ Recent posts