For example:
A B C D E F G H I J K L M N O P Q R S T U V W X Y E D J C I O B H N T A G M S Y F L R X K Q W P V U
Ideas such as:
Outside the diamond is a space, within the diamond (can use function to judge) There are two kinds of points, one is a character, one is a space
It can be found that there is a character position (col-row)%2 = = 0; next look for a 45 degree diamond and rectangle correspondence, row ' = (col-row)/2, col ' =col-row '
The complete code is as follows:
Public class printmatrixtrans45degree { Public Static void Main(string[] args) {System.out.println ("Hello world!");intC=0;Char[] arr =New Char[5][5]; for(inti =0; I <5; i++) { for(intj =0; J <5; J + +) {arr[i][j]= (Char)(' A '+ c); C + +; } } for(inti =0; I <5; i++) { for(intj =0; J <5; J + +) {System.out.print (arr[i][j]+" "); } System.out.println (); } for(inti =4; I >=-4; i--) {introw =0;intCol =0; for(intj =0; J <=8; J + +) {if(Isarea (I,J)) {if((j-i)%2==0){//Print lettersrow = (j-i)/2; col = J-row; System.out.print (Arr[row][col]); }Else{System.out.print (" "); } }Else{//Print spaceSystem.out.print (" "); }} System.out.println (); } } Public Static Boolean Isarea(intRow,intCol) {if(Row <= col && Row >= Col-8&& row >=-col && row <=-col +8){//system.out.println ("(" +row+ "," +col+ ")"); return true; }return false; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java rotates the matrix 45-degree output