Statement Exercise 6. Statement exercise questions

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.