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;
}
}
}
본 논문이 여러분의 자바 프로그램 설계에 도움이 되기를 바랍니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
38. Java의 Leetcode 솔루션텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.