Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
RamaKrishna Thota
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to create an array to return, the current year and a loop.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic