1
import java.io.*;
2
public class ArrayPrint
3

{
4
private int N;
5
private int[][] intarray;
6
ArrayPrint()
7
{
8
N=5;
9
intarray=new int[N][N];
10
}
11
ArrayPrint(int n)
12
{
13
N=n;
14
intarray=new int[N][N];
15
}
16
public void Print()
17
{
18
int i=0,j=0;
19
int i0=0,j0=0;
20
int count=1;
21
int Num=N-1;
22
while(Num>0)
23
{
24
for(i=i0,j=j0;j<Num;j++,count++)
25
{
26
intarray[i][j]=count;
27
}
28
for(i=i0;i<Num;i++,count++)
29
{
30
intarray[i][j]=count;
31
}
32
for(j=Num;j>j0;j--,count++)
33
{
34
intarray[i][j]=count;
35
}
36
for(i=Num;i>i0;i--,count++)
37
{
38
intarray[i][j]=count;
39
}
40
i0++;
41
j0++;
42
Num--;
43
}
44
if(N%2!=0)
45
{
46
intarray[N/2][N/2]=count;
47
}
48
for(i=0;i<N;i++)
49
{
50
for(j=0;j<N;j++)
51
{
52
String ar="0";
53
if(intarray[i][j]/10<1)
54
{
55
ar=" "+intarray[i][j];
56
}
57
else if(intarray[i][j]/100<1 && intarray[i][j]/10>=1)
58
{
59
ar=" "+intarray[i][j];
60
}
61
System.out.print(ar+" ");
62
}
63
System.out.println();
64
}
65
}
66
public static void main(String[] args) throws IOException
67
{
68
int order=0;
69
System.out.println("Please input the order of the square:(<10:)");
70
order=System.in.read();
71
order=order-'0';
72
ArrayPrint arr=new ArrayPrint(order);
73
arr.Print();
74
}
75
}

2

3



4

5

6

7



8

9

10

11

12



13

14

15

16

17



18

19

20

21

22

23



24

25



26

27

28

29



30

31

32

33



34

35

36

37



38

39

40

41

42

43

44

45



46

47

48

49



50

51



52

53

54



55

56

57

58



59

60

61

62

63

64

65

66

67



68

69

70

71

72

73

74

75
