Package COM. WZS; // Add difficulty to the first question. Use the numbers 1, 2, 3, 4, and 5 to write a main function in Java and print out all the different orders, // For example, 51234, 12345, etc., the requirement: "4" cannot be In the third place, "3" and "5" cannot be connected. Public class test3 {public static void main (string [] ARGs) {int number = 0; int COUNT = 0; string numberstr; For (int A = 1; A <= 5; A ++) {for (INT B = 1; B <= 5; B ++) {for (INT c = 1; C <= 5; C ++) {for (INT d = 1; D <= 5; D ++) {for (int e = 1; E <= 5; E ++) {// print all non-repeated numbers if (! = B &! = C &! = D &! = E & B! = C & B! = D & B! = E & C! = D & C! = E & D! = E) {number = A * 10000 + B * 1000 + C * 100 + D * 10 + E; numberstr = string. valueof (number); // 4 can no longer contain 3rd bits, and "3" and "5" cannot be connected if (numberstr. indexof ("4 ")! = 2 & numberstr. indexof ("35") =-1 & numberstr. indexof ("53") =-1) {count ++; system. out. println (numberstr) ;}}}}} system. out. println ("Count =" + count );}}
Output result:
1234512543132451325414325145231523415243213452154323145231542431524513251342514331245312543152431542321453215432514325413412534152342153425134512345214132541523423154251343125431524321543251451234513245213452315123451243513245134252134521435231452341541235413254213542315431254321 COUNT = 56