Results 1 to 6 of 6
 03292017, 10:55 AM #1Member
 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.
 03292017, 02:09 PM #2
Re: Need help to find permuted numbers in java
Please post code with the proper indentations and some comments describing its logic.
If you don't understand my response, don't ignore it, ask a question.
 03292017, 03:34 PM #3
Re: Need help to find permuted numbers in java
It's all over
https://coderanch.com/t/677809/java/codeprogram
Java Code Help  ElaKiri Community
Also apparently posted and moderated out of existence at SO
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 03292017, 04:31 PM #4Senior 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,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 03292017, 04:41 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 29
Re: Need help to find permuted numbers in java
Use a digital expansion of 1/7
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
 03292017, 05:24 PM #6Senior 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,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads

How to find biggest two int. numbers from four
By keimic53 in forum New To JavaReplies: 5Last Post: 05242014, 04:36 AM 
Can StreamTokenizer find numbers followed by letters
By kbreitsprecher in forum New To JavaReplies: 1Last Post: 03082012, 11:45 PM 
Coding to find the Harshad numbers...
By nope in forum New To JavaReplies: 16Last Post: 03072011, 05:16 AM 
Find the sum of two numbers that are from two different arrays.
By bMorgan in forum New To JavaReplies: 8Last Post: 02082011, 08:27 AM 
Help with my code to find MinOfAll numbers
By May.ver.rick in forum New To JavaReplies: 9Last Post: 04202010, 05:46 AM
Bookmarks