File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Missing numbers from a sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Missing numbers from a sequence" Watch "Missing numbers from a sequence" New topic
Author

Missing numbers from a sequence

divya madala
Ranch Hand

Joined: Jan 10, 2001
Posts: 61
Hi All,
Can anybody give me a code where I should have the output of missing numbers from a sequence.
For example if I have a list
12340
12342
12343
12345
12346
12347
12348
12350
then my output should be 12341,12344,12349. I know this's a homework assignment, but I would appreciate any help you could offer.
Thanks for your help,
Divya
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Without giving too much away, here's a general approach. You want two control numbers, one representing the value from the file, and another representing the next number in the sequence.
Read in the first number and convert it to an integer, saving the value twice, both as the file value and the sequence value. Then set up a loop where you compare the two values (which will be the same the first time through the loop). If they are the same, then read in the next value and increment the sequence number. If they are different, print out the sequence number and increment it, but don't read in a value from the file.
Keep looping until you run out of values.
I could have described this more cleanly in pseudo-code, but I didn't want to give too much away.
Try coding it, and when you run into something you can't solve post the code that you have and get further comments.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Missing numbers from a sequence
 
Similar Threads
Fibonacci numbers are 0 and 1.
Oracle order of insertion
Fibonacci Sequence Problem
Predict Sequence of Numbers?!
How to Add a Line Counter for Each XML Element in XSL?