Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: need a help to do this Question

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default need a help to do this Question

    I tried to do this question.But I can't take a right approach. This is the question:

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
    It can be seen that the number, 125874 and its double ,251748 contain exactly the same digits,but in a different order.Write a java program to find to find & print the smallest positive integer "x",such as "2x,3x,4x,5x and 6x" contain the same digits.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~

    I need to do it only using Arrays.(except in String method & regex).


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: need a help to do this Question

    Show what you've tried. Start simple with the 2x and 3x case and then expand from there.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: need a help to do this Question

    I haven't clear idea to solve this this question.can you help me to do that??

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: need a help to do this Question

    For the simplified approach (2x/3x only), the brute force method would be to start with x = 1, multiply by 2 and 3 to get 2x and 3x and then check if 2x and 3x contain the same digits. If x = 1 is not the 2x/3x answer, then repeat with x + 1. Continue repeating until the 2x/3x answer is found.

    What part of this approach didn't occur to you and/or are you unable to program? Pretty basic stuff if you think it through. Maybe writing your ideas down on paper or electronic notepad first would be helpful. That's kind of what I was doing here as I explained it to you.

  5. #5
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: need a help to do this Question

    ok. I think the the minimum number must be contain more than 6 digits.So I want to check each number digit by digit until find the minimum number.I want to create an Array to do that.But I can't construct it?I need a code to do that

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: need a help to do this Question

    I recommend you review the Arrays Tutorial. We won't give you code, but we'll help you with code you've written.

Similar Threads

  1. Replies: 1
    Last Post: November 4th, 2013, 05:38 AM