This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes How to get last ten years in one Array based on Current Year Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get last ten years in one Array based on Current Year" Watch "How to get last ten years in one Array based on Current Year" New topic
Author

How to get last ten years in one Array based on Current Year

RamaKrishna Thota
Greenhorn

Joined: May 17, 2011
Posts: 12
Hi All,


I have a requirement like, i have to get last ten years in one Array based on current year.

I am calling lastTenYears() method that method should be return last ten years in one Array like{2001,2002,2003,.......2011}
Please help me anybody Please.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You'll need to create an array to return, the current year and a loop.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I'm guessing this doesn't need to support crossing the AD/BC point in history? If so, getting the current year (using the Calendar get method) and subtracting ten will do.

If you do need to support the point in time years start to go up in number again, Calendar has an add method. You could start with the date ten years ago, add a year and put it in your array.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get last ten years in one Array based on Current Year