File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

combination of non repeating 9 digit numbers

 
krishna kumar.s
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but this is 9! results. (9*8*7*6*5*4*3*2=362880)

Is it ok?
 
Wesleigh Pieters
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so confused by that post now O_o
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want a combination, or ALL combinations?
 
krishna kumar.s
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic