aspose file tools*
The moose likes Beginning Java and the fly likes narrow down a range algorithm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "narrow down a range algorithm" Watch "narrow down a range algorithm" New topic
Author

narrow down a range algorithm

Joe Robles
Greenhorn

Joined: Jan 13, 2009
Posts: 11
Hi all,

I have a range of two date values. I need to write logic that keeps breaking the range further into lesser ranges till no more ranges are avaiable.

Is there any algorithm that I can use to do this in java.

Any help is highly appreciated.

Thanks in advance for your valuable time and interest.

Example:

start date - 01-01-1981
end date - 01-01-1988

The program must add the above and divide by 2 repeatedly so I get the following ranges.

1981-1988
1988-1994
1994-2000
2000-2006


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

The program must add the above and divide by 2 repeatedly so I get the following ranges.

1981-1988
1988-1994
1994-2000
2000-2006



Can you elaborate your example a bit? I don't see any adding and divide by 2 going on.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Joe Robles
Greenhorn

Joined: Jan 13, 2009
Posts: 11
Hi

My bad.

New example:

Date range that needs to be broken: 1960 - 2000

I chose to add the above values and divide by two; and need to repeat the same for each of the resultant ranges; then the resultant ranges need to end up like this:

1960 - 1965
1965 - 1970
1970 - 1975
1975 - 1980
1980 - 1985
1985 - 1990
1990 - 1995
1995 - 2000


Hope this helps...

Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36452
    
  15
Those aren't divided ranges. They have an overlap. What you actually want is
1961 to 2000

1961 to 1980, 1981 to 2000

1961 to 1970, 1971 to 1980, 1981 to 1990, 1991 to 2000, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: narrow down a range algorithm
 
Similar Threads
java.text.ParseException in Web service
Exhausted Resultset exception when result count is huge.
validating a range of values
Bush Said High Unemployment In IT Sector Is Due To Our Outdated Skills
is that any utility class that help compare date within start and end date ?