Typical Java questions> long-term updates and typical java questions
1. The array is rotated 90 degrees clockwise.
1 2 // The array rotates 90 ° clockwise. 3 // The column changes to the row (positive 0 column --> 0 row, 1 column --> 1 row ...) 4 // change the row column (the opposite is 0 rows --> length-1 column, 1 row --> length-2 column ...) 5 public class Rotate {6 public static void getRotate (int [] [] x) {7 8 int [] [] B = new int [x [0]. length] [x. length]; 9 // converts 10 for (int I = 0; I <x. length; I ++) {11 for (int j = 0; j <x [I]. length; j ++) {12 B [j] [x. length-I-1] = x [I] [j]; 13} 14} 15 // output 16 for (int I = 0; I <B. length; I ++) {17 for (int j = 0; j <B [I]. length; j ++) {18 System. out. print (B [I] [j] + ""); 19} 20 System. out. println (); 21} 22 23} 24 // Test 25 public static void main (String [] args) {26 int [] [] a = {0, 1, 2}, 27 {0, 1, 5}, 28 {1, 1, 6}, 29 {1, 2, 5}, 30 {1, 2, 5} 31}; 32 getRotate (a); 33} 34}
Running result:
1 1 1 0 0
2 2 1 1 1
5 5 6 5 2
2, 9-9 multiplication table
1/** 8, 9 multiplication table */2 public class Job8 {3 4 public static void main (String [] args) {5 for (int I = 1; I <= 9; I ++) {6 for (int j = 1; j <= I; j ++) {7 System. out. print (j + "*" + I + "=" + I * j + "\ t"); 8} 9 System. out. println (); 10} 11} 12}
Running result: