Task

Determine whether a given year is a leap year in the Gregorian calendar.



See also

 Leap year (wiki)


/* NetRexx */
 
options replace format comments java crossref savelog symbols nobinary
 
years = '1500 1580 1581 1582 1583 1584 1600 1700 1800 1900 1994 1996 1997 2000 2004 2008 2009 2010 2011 2012 2100 2200 2300 2400 2500 2600'
years['l-a'] = ''
years['n-a'] = ''
years['l-j'] = ''
years['n-j'] = ''
 
loop y_ = 1 to years.words
  year = years.word(y_)
  if isLeapyear(year) then years['l-a'] = years['l-a'] year
                      else years['n-a'] = years['n-a'] year
  if GregorianCalendar().isLeapYear(year) then years['l-j'] = years['l-j'] year
                                          else years['n-j'] = years['n-j'] year
  end y_
 
years['l-a'] = years['l-a'].strip
years['n-a'] = years['n-a'].strip
years['l-j'] = years['l-j'].strip
years['n-j'] = years['n-j'].strip
 
say ' Sample years:' years['all'].changestr(' ', ',')
say '     Leap years (algorithmically):' years['l-a'].changestr(' ', ',')
say '     Leap years (Java library)   :' years['l-j'].changestr(' ', ',')
say ' Non-leap years (algorithmically):' years['n-a'].changestr(' ', ',')
say ' Non-leap years (Java library)   :' years['n-j'].changestr(' ', ',')
 
return
 
-- algorithmically
method isLeapyear(year = int) public constant binary returns boolean
  select
    when year // 400 = 0 then ly = isTrue
    when year // 100 \= 0 & year // 4 = 0 then ly = isTrue
    otherwise ly = isFalse
    end
  return ly
 
method isTrue public constant binary returns boolean
  return 1 == 1
 
method isFalse public constant binary returns boolean
  return \isTrue