###前提・実現したいこと
学校の課題にて2017年から2019年までのカレンダーをjavaで作成するというものが出ました。日にちはしっかりと表示されるようになったのですが、曜日と正月から何日経ったかの表示がうまくいきません。それを表示できるようにしたいです。
###発生している問題・エラーメッセージ
2018・1・1は実際は月曜であるのに火曜と表示される。
2018・1・1は[1/365]であるのに[366/365]と表示される。
###該当のソースコード
class PCHK1 {
public static void main (String[] args){
int i;
int year = Integer.parseInt(args[0]);
int month=Integer.parseInt(args[1]);
int day=Integer.parseInt(args[2]);
int[] m={0,31,28,31,30,31,30,31,31,30,31,30,31};
int count = 1;
if ( year==2017 ){ String[] week= {"Sat","Sun","Mon","Tue","Wed","Thu","Fri"}; for(i=1; i<month; i++){ count=count+m[i]; } count=count + (year-2017)*365; System.out.println("2017:"+month+":"+day+":"+week[count%7]+":("+count+"/365)"); } else if ( year==2018 ){ String[] week= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; for(i=1; i<month; i++){ count=count+m[i]; } count=count + (2018-2017)*365; System.out.println("2018:"+month+":"+day+":"+week[count%7]+":("+count+"/365)"); } else if ( year==2019 ){ String[] week= {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"}; for(i=1; i<month; i++){ count=count+m[i]; } count=count + (2019-2017)*365; System.out.println("2019:"+month+":"+day+":"+week[count%7]+":("+count+"/365)"); } }
}
###試したこと
色々試していますが、なかなかできません。
###補足情報(言語/FW/ツール等のバージョンなど)
MacBookAir
tool:mi
ターミナル(MacBook搭載)
回答2件
あなたの回答
tips
プレビュー