Java Algorithm Little knowledge Exercise

Source: Internet
Author: User

Occasionally opened the previous exercises, unconscious and want to knock once again, although some ideas are still so old-fashioned, but after all, is also a consolidation of knowledge.

First, the title: There are 1, 2, 3, 44 numbers, can make up how many different and no duplicate number of three digits? How much are they?

The specific idea is simple, is to take out a number, with the other three of any two non-repeating groups, and finally add up,

/*** Title: There are 1, 2, 3, 44 numbers, can make up how many different and no repetition of the number of three digits? How much are they? * Time: March 10, 2016 21:34:15 **/ Public classZushu { Public Static voidMain (string[] args) {intnum= 0,count=0;  for(intI =1;i<5;i++){             for(intJ =1;j<5;j++){                 for(intk=1;k<5;k++){                    if(i!=j && i!=k && j!=k) {num= i*100+j*10+K; Count++; System.out.print (Num+" "); } }}} System.out.println (""); System.out.println ("Number is:" +count); }}

Printing results are:

123 124 132 134 142 143 213 214 231 234 241 243 312 314 321 324 341 342 412 413 421 423 431 432个数为:24

This idea is a more stupid way, for a lot of times, not too suitable, nested loops too much, I hope the great God has a good algorithm, a lot of corrections!

  

Java Algorithm Little knowledge Exercise

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.