java 月第一天星期几_JAVA显示每月第一天星期几

importjava.util.Scanner;publicclassExercise{publicstaticvoidmain(String[]args){Scannerinput=newScanner(System.in);System.out.println("Enterthefirstdayofayear");intfirstDa...

import java.util.Scanner;public class Exercise {public static void main(String[] args){Scanner input=new Scanner(System.in);System.out.println("Enter the first day of a year");int firstDay=input.nextInt();System.out.println("Enter the year");int year=input.nextInt();int numberOfMonth=0;for(int month=1;month<=12;month++){switch(month){case 1:System.out.print("January "+year+" is ");numberOfMonth=30;break;case 2:System.out.print("February "+year+" is ");if((year%4==0&&year%100!=0)||year%400==0)numberOfMonth=29;elsenumberOfMonth=28;break;case 3:System.out.print("March "+year+" is ");numberOfMonth=31;break;case 4:System.out.print("April "+year+" is ");numberOfMonth=30;break;case 5:System.out.print("May "+year+" is ");numberOfMonth=31;break;case 6:System.out.print("June "+year+" is ");numberOfMonth=30;break;case 7:System.out.print("July "+year+" is ");numberOfMonth=31;break;case 8:System.out.print("August "+year+" is ");numberOfMonth=31;break;case 9:System.out.print("September "+year+" is ");numberOfMonth=30;break;case 10:System.out.print("October "+year+" is ");numberOfMonth=31;break;case 11:System.out.print("November "+year+" is ");numberOfMonth=30;break;case 12:System.out.print("December "+year+" is ");numberOfMonth=31;break;}switch (firstDay) {case 0: System.out.println("Sunday"); break;case 1: System.out.println("Monday"); break;case 2: System.out.println("Tuesday"); break;case 3: System.out.println("Wednesday"); break;case 4: System.out.println("Thursday"); break;case 5: System.out.println("Friday"); break;case 6: System.out.println("Saturday"); break;}****** *****}}}末尾星号处有疑问,请见图,求解第一张图和第二张图中firstDay的变化过程和原因,为什么firstDay=firstDay+numberOfMonth打进去之后和第一张图的数据就不一样了?

错了,这是另一张

展开

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值