This week's book giveaway is in the
General Computing
forum.
We're giving away four copies of
Arduino in Action
and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
"date" sorting program
ankur rathi
Ranch Hand
Joined: Oct 11, 2004
Posts: 3829
posted
Jan 25, 2008 06:04:00
0
"date" sorting program:
package com.ankur; public class Date { int dd; int mm; int yy; Date(int dd, int mm, int yy) { this.dd = dd; this.mm = mm; this.yy = yy; } public boolean isSuppliedDateLatest(Date date) { boolean latest = false; if(date.yy > this.yy) { latest = true; } else if(date.yy == this.yy && date.mm > this.mm) { latest = true; } else if(date.yy == this.yy && date.mm == this.mm && date.dd > this.dd) { latest = true; } return latest; } } package com.ankur; public class DateSort { public static void main(String[] args) { Date[] dates = new Date[5]; dates[0] = new Date(31,12,1982); dates[1] = new Date(15,12,1981); dates[2] = new Date(14,12,1980); dates[3] = new Date(18,11,1985); dates[4] = new Date(18,8,2004); //System.out.println(dates[0].isSuppliedDateLatest(dates[4])); dates = DateSort.sortDates(dates); for(int i = 0; i < dates.length; i++) { System.out.println(dates[i].dd + "," + dates[i].mm + "," + dates[i].yy); } } public static Date[] sortDates(Date[] dates) { Date aDate = null; Date bDate = null; for (int i = 0; i < dates.length - 1; i++) { for (int j = 0; j < dates.length - 1; j++) { aDate = dates[j]; bDate = dates[j + 1]; if (!aDate.isSuppliedDateLatest(bDate)) { dates[j + 1] = aDate; dates[j] = bDate; } } } return dates; } }
Post you comments.
Mark Newton
Ranch Hand
Joined: Jan 31, 2006
Posts: 129
posted
Jan 25, 2008 06:19:00
0
It's beautiful.
[ January 25, 2008: Message edited by: David Payne ]
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: "date" sorting program
Similar Threads
Problem with saving a state in calendar program.
string to date
Getting a Date from a String
public boolean equals (Object obj)
Help with printing appointments
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter