Win a copy of The Java Performance Companion this week in the Performance forum!

# combination of non repeating 9 digit numbers

krishna kumar.s
Greenhorn
Posts: 22
Can anybody tell me step by step approach to create a combination of numbers using 123456789 . Any link or algorithm would be helpful. I am a begginer in Java your input is highly appreciated.

Suryanarayana murthy
Greenhorn
Posts: 3
• 1
I am not clear about your question. Please be clear and specific. What do you want to do with the numbers. What is the output you are expecting

Thanks & Regards
Surya

Wesleigh Pieters
Ranch Hand
Posts: 81
Suryanarayana murthy wrote:I am not clear about your question. Please be clear and specific. What do you want to do with the numbers. What is the output you are expecting

Thanks & Regards
Surya

ditto

krishna kumar.s
Greenhorn
Posts: 22
I want to create combination of 9 digit numbers using 9 numbers . for example 123456789,213456789, 312456789 etc . To solve a puzzle I need them. numbers should not repeat.

Wesleigh Pieters
Ranch Hand
Posts: 81
there might be an easier way to do it with just a normal array but this works:

I just created an arraylist of Integers, added the numbers 1-9 into it and then used the Collections shuffle method on it.

edit, sorry you want it to be one number made out of that?

if so this works, not very tidy but yeah I am newish to JAVA and programming.

Ivan Franko
Ranch Hand
Posts: 46
but this is 9! results. (9*8*7*6*5*4*3*2=362880)

Is it ok?

Wesleigh Pieters
Ranch Hand
Posts: 81
so confused by that post now O_o

Matthew Brown
Bartender
Posts: 4567
8
I'd go with Wesleigh's approach of using Collections.shuffle(). Simple, and as random as you're going to realistically get.

fred rosenberger
lowercase baba
Bartender
Posts: 12145
30
Do you want a combination, or ALL combinations?

krishna kumar.s
Greenhorn
Posts: 22
I want all possible combinations of 9 digit numbers which uses only 123456789 with a condition same number should not repeat.

fred rosenberger
lowercase baba
Bartender
Posts: 12145
30
Ok. The first thing that you need to do is FORGET about java, computers, data structures, methods, etc.

suppose someone gave you 9 tiles, each with a single digit on it.

How would you go about arranging them so that you would know for a fact that when you are done, you have gotten to every possible arrangement?

Campbell Ritchie
Sheriff
Posts: 49382
62
362880 is not that many for a computer to store. But whoever said that is correct; that is how many numbers there are with 9 digits all different.