1 //The Magic matrix is incremented by default from the upper-right corner 45 degrees2 //@ Overland--595128841 in qq dot com3 //import java.util.Arrays;//for printing API functions4 Public classRubik's Cube matrix5 {6 Public Static voidMain (string[] args)7 {8 intn = 7;9 intA =0;Ten intb = (n-1)/2; One int[] arr =New int[n][n]; A for(inti=1;i<=n*n;i++) - { - if(i==1) the { -Arr[a][b]=1; -}Else - { +A-=1; -B+=1; + if((i-1)%n==0) A { at -a+=2; -B-=1; -Arr[a][b]=i+1; -}Else if(a<0) - { inA=n-1; -arr[a][b]=i; to}Else if(b>n-1) + { -B=0; thearr[a][b]=i; * } $ Else{Panax Notoginsengarr[a][b]=i; - } the } + //System.out.println (Value of "I: Value of" +i+ "A: Value of" +a+ "B:" +b "); //show the relationship between A and B A } the //System.out.print (arrays.deeptostring (arr)); print two-dimensional array API functions + //You can also use the following for statement instead - for(inti=0;i<arr.length;i++) $ { $ for(intj=0;j<arr[i].length;j++) - { -System.out.print (arr[i][j]+ ""); the } - //line BreakWuyi System.out.println (); the } - } Wu}
Magic Matrix Java code