122345 arrange randomly to find the number that satisfies the condition

Source: Internet
Author: User

Title Requirements:

1. Must contain 122345 of these six numbers

2. The third digit in the number (hundred) cannot be 4

3. Output 6 digits of all the above two conditions

The code is as follows:

    StaticString[] Numberstrings = {"1", "2", "3", "4", "5"};  Public Static voidMain (string[] args) { for(inti=122345;i<999999;i++) {Onetof (i+""); }            }     Public Static voidOnetof (FinalString number) {         for(String n:numberstrings) {if(Number.indexof (n) <0)                return; }        if(Number.indexof ("4") ==3)            return; if(Number.lastindexof ("2") ==number.indexof ("2")))            return; if("Number.indexof") >0 | | number.indexof ("(") > 0)            return;    SYSTEM.OUT.PRINTLN (number); }

So, the question is, if it's not a 6-digit number, but a 7-bit, or a lot of other bits, you need to change it:

if (Number.indexof ("4") = = Number.length ()-3            ) return;

That's it.

But this method feel inefficient, if there is an idea, welcome message ....

122345 arrange randomly to find the number that satisfies the condition

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.