Statement Exercise 6. Statement exercise questions
There are four numbers: 1, 2, 3, and 4. How many three numbers can be composed of different and non-repeated numbers? What is it?
1 String str = ""; 2 // first, store all the three digits in the String and separate them with #. 3 for (int I = 1; I <= 4; I ++) {4 for (int j = 1; j <= 4; j ++) {5 for (int k = 1; k <= 4; k ++) {6 int num = I * 100 + j * 10 + k; 7 str = num + "#" + str; 8} 9} 10} 11 // split the String by # and output the three digits of the String type 12 String s [] = str. split ("#"); 13 String a, B, c; 14 int count = 0; 15 // The array traverses each element and truncates each bit to compare 16 for (int I = 0; I <s. length; I ++) {17 a = s [I]. substring (0, 1); 18 B = s [I]. substrin G (1, 2); 19 c = s [I]. substring (2, 3); 20 if (. equals (B) = false & B. equals (c) = false &. equals (c) = false) {21 System. out. println (s [I]); 22 count ++; 23} 24} 25 System. out. println ("Total" + count +. ");
1 int count1 = 0; 2 for (int I = 1; I <= 4; I ++) {3 for (int j = 1; j <= 4; j ++) {4 for (int k = 1; k <= 4; k ++) {5 // determine that as long as the three numbers are different, they form three digits and output 6 if (I! = J & I! = K & j! = K) {7 int num1 = I * 100 + j * 10 + k; 8 count1 ++; 9 System. out. println (num1); 10} 11} 12} 13} 14 System. out. println ("Total" + count1 +. ");
Result: