# Thread: Need help to find permuted numbers in java

1. Member
Join Date
Mar 2017
Posts
1
Rep Power
0

## Need help to find permuted numbers in java

It is 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 and print the smallest positive integer, x such that 2x, 3x, 4x, 5x and 6x contain the same digits.

This is the question. I tried to do only for 2x numbers. But very hard to do it.

Java Code:
```public static void main(String[] args)
{
int num1=0, tmp1, num2, multi1, multi2, sum1, sum2, len1, len2;
do{
num1++;
tmp1 = num1;
num2 = num1 * 2;
multi1 = 1;
multi2 = 1;
sum1 = 0;sum2 = 0;len1 = 0;len2 = 0;
while (tmp1 != 0)
{
multi1 *= ((tmp1 % 10 == 0) ?1: tmp1 % 10);
sum1 += (tmp1 % 10);
tmp1 /= 10;
len1++;
}
while (num2 != 0)
{
multi2 *= ((num2 % 10 == 0) ?1: num2 % 10);
sum2 += num2 % 10;
num2 /= 10;
len2++;
}

if (multi1 == multi2 && sum1==sum2 && len1==len2)
{
System.out.println("permuted");
}
}while((multi1!=multi2) || (sum1!=sum2) || (len1!=len2));
System.out.println(num1);
}
}```

This is the code I tried. Get multiple, sum and length. But some numerics such as 225, 225*2=450
This also get the same multiplication, sum and number length. But they are not permuted.

2. ## Re: Need help to find permuted numbers in java

Please post code with the proper indentations and some comments describing its logic.

3. ## Re: Need help to find permuted numbers in java

It's all over
https://coderanch.com/t/677809/java/code-program
Java Code Help - ElaKiri Community

Also apparently posted and moderated out of existence at SO

db

4. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: Need help to find permuted numbers in java

Hey @OP, did you do a web search for permutation algorithms? You should get lots of hits.

Regards,
Jim

5. ## Re: Need help to find permuted numbers in java

Use a digital expansion of 1/7

kind regards,

Jos

6. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: Need help to find permuted numbers in java

@OP, you don't need to do any math on this except for the required multiplication.
In the solution, each number will have the same digits. So consider how using a
sort method might help.

Regards,
Jim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•