Skip to content

Instantly share code, notes, and snippets.

@skRyo
Created July 11, 2012 10:53
Show Gist options
  • Save skRyo/3089637 to your computer and use it in GitHub Desktop.
Save skRyo/3089637 to your computer and use it in GitHub Desktop.
グレゴリオ的な
/*
* 西暦年が4で割り切れる年は閏年
ただし、西暦年が100で割り切れる年は平年
ただし、西暦年が400で割り切れる年は閏年
*
*/
public class gregoriano {
public static void main(String[] args) {
int x = 1000;
for ( int i = 1; i <= x; i++ ){
if ( i%4==0 ){
if ( i%400==0 || i%100!=0 ){
System.out.println(i + " 閏年みたいだよ");
}else{
System.out.println(i);
}
}else{
System.out.println(i);
}
}
}
}
@giuniu
Copy link

giuniu commented Jul 11, 2012

if (i % 4 && (i % 100 != 0 || i % 400)) で良いんじゃないかな?

@skRyo
Copy link
Author

skRyo commented Jul 11, 2012

確かにその通りでございます。。

@giuniu
Copy link

giuniu commented Jul 12, 2012

あ、色々抜けてた。しかもまだ冗長だな。
if ((i % 4 == 0) && (i % 100 != 0) || (i % 400 == 0))
でFA。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment