guys can u help me this!!!..

int n=137;

and i want to display like this!!!...

173,371,317,731,713

one variable each of them...

Printable View

- 01-26-2011, 11:21 PMjhon123help me please!!!.. im new in java..
guys can u help me this!!!..

int n=137;

and i want to display like this!!!...

173,371,317,731,713

one variable each of them... - 01-26-2011, 11:26 PMsunde887
Did you ask this question the other day? You need to develop a permutation method:

Permutation - Wikipedia, the free encyclopedia - 01-27-2011, 11:28 PMjhon123
awts!!!!.... i dnt understand..... can u give me some hint!!....

- 01-27-2011, 11:43 PMJunky
A hint???

Other than a link to the Wiki page explaining permutations? Did you even bother to read it or do you just want someone to spoonfeed you the code? - 01-27-2011, 11:49 PMJojomofoman
- 01-27-2011, 11:50 PMsunde887
The idea of a permutation is to re-arrange some input into every possible re-arrangement.

for the number 123, when you apply the permutation it should output:

123, 213, 231,

321. 312. 132.

Do you notice any pattern that seems to be re-occurring?

I split it into 2 lines, look at how the one is moving in the first line. To find out how many combination's there will be in a number after permutation you use factorials, if the item has a length of 3, it would be 3 * 2 * 1 = 6 possible changes.

Permutations are pretty challenging, and I'd have to sit down and think about how to do them in java, but just use what I said here and try to think how you would do it yourself.

You can split the number you are applying this to with % and /, it would probably also be easier to temporarily set them as strings.

Also, try using some other numbers and solving it by hand, then take what you did an translate it to java.

I gave you a lot to go on, and I will admit that permutations are fairly challenging, so just take your time, think everything through, read more about it on the wiki page and just keep considering how to do it. - 01-28-2011, 03:12 AMadela
This is interesting! I'll give you a hint. There's a math formula for this, apply it in your java code.

- 01-28-2011, 06:32 AMjhon123
tnx master I get the pattern!!!... but so hard to code the frmula in java!!!... but i will try my best!!!... btw tnx...

- 01-28-2011, 08:19 AMsubith86a tricky way out (may not be the most intelligent way)
Apart from formula, I think you can also do something like this.

Code:`String number1 = "1";`

String number3 = "3";

String number7 = "7";

// Dont hardcode like i have shown above. Put each number to each string. find out the way to convert Integer to String

for (int i = 100; i < 1000; i++) {

String testNumber = convertToString(i); //find out the way to convert Integer to String

//now testNumber will contain something like "137" or "138" till "999"

if ( testNumber.contains(number1) &&

testNumber.contains(number3) &&

testNumber.contains(number7)) //Remember, there is no method called contains. Find it out yourself.

{

System.out.println(testNumber);

}

}

- 01-28-2011, 08:37 AMJosAH
I supplied working code in this thread.

kind regards,

Jos - 01-29-2011, 05:02 AMjhon123
ahh tnx!!!!.... actually this is the whole tread..

A number is "prime" if it has no divisors other than itself and1. For example, 23 is prime

and 35 is not prime because 35 = 7 x 5. If the digits of a number are rearranged, then

usually its primeness changes - for example, 32 is not prime but 53 is. For this problem,

you have to find numbers which are prime no matter how you rearrange their digits. For

example, all of the numbers 113, 131 and 311are prime, so we say that 113 is an

"anagrammatic prime" (also 131 and 311 are anagrammatic primes).

Input will be from standard input and will consist of lines with a single positive number, n,

less than 10,000,000, on each line. You must find the first anagrammatic prime which is

bigger than n and less than the next power of 10 above n. The input will be terminated

by a line consisting of a single 0.

Output, which must be written to standard output, must be one number for each number

in the input. The number must either be the next anagrammatic prime, as described

above or 0 if there is no anagrammatic prime in the range defined.

Example

Input

10

16

900

113

0

Output

11

17

919

131

0

- 01-29-2011, 10:59 PMsunde887
Were you able to solve it?

- 01-30-2011, 05:28 AMjhon123
yes!!!.. so hard to code for me!... i know how to get the prime num!... but i dnt know how to get a anagrammatic prime.... that's why i ask on how to get a ramble input.... anyOne can help me..

- 01-30-2011, 08:20 AMJosAH