java 회전 2차원 그룹 실례

2454 단어 java수조
본고는 자바 회전 2차원 그룹의 조작을 실례로 서술하여 모두에게 참고하도록 제공한다.구체적인 실현 방법은 다음과 같다.

package test;
/*
 *     1    2    3    4    5   
 *    16    17    18    19    6   
 *    15    24    25    20    7   
 *    14    23    22    21    8   
 *    13    12    11    10    9
 *
 *    , , 1 。
 * */
public class Test6
{
    public static void main(String[] args)
    {
        arraynum(4);
    }
    // .. y
    private static void arraynum(int x)
    {
        int[][] arr = new int[x][x];
        int len = arr.length, max = 0, count = 0;
        specArr(arr, len, max, count);
        arrprint(arr);
    }
    // for
    private static void arrprint(int[][] arr)
    {
        for (int[] in : arr)
        {
            for (int t : in)
            {
                System.out.print(t + "\t");
            }
            System.out.println();
        }
    }
    private static void specArr(int[][] arr, int len, int max, int count)
    {
        while (len > 0)
        {
            int j = 0;
            for (int index = 0; index < (len - 1) * 4; index++)
            {
                if (index < len - 1)
                    arr[0 + count][index + count] = ++max;
                else if (index < 2 * (len - 1))
                    arr[count + j++][arr.length - 1 - count] = ++max;
                else if (index < 3 * (len - 1))
                    arr[arr.length - 1 - count][(j--) + count] = ++max;
                else if (index < 4 * (len - 1))
                    arr[arr.length - 1 - (j++) - count][0 + count] = ++max;
            }
            if (len == 1)
            {
                arr[arr.length / 2][arr.length / 2] = max + 1;
            }// y , n=1 ,
            count++;
            len = len - 2;
        }
    }
}
본 논문이 여러분의 자바 프로그램 설계에 도움이 되기를 바랍니다.

좋은 웹페이지 즐겨찾기