JAVA显示每月第一天星期几 20

importjava.util.Scanner;publicclassExercise{publicstaticvoidmain(String[]args){Scanne... 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打进去之后和第一张图的数据就不一样了?
错了,这是另一张
展开
 我来答
891377446
2016-07-21 · TA获得超过475个赞
知道小有建树答主
回答量:172
采纳率:0%
帮助的人:96.8万
展开全部
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
System.out.println(cal.get(Calendar.YEAR)+" "+(cal.get(Calendar.MONTH)+1)+" "+cal.get(Calendar.DAY_OF_MONTH)+" ");
int i = cal.get(Calendar.DAY_OF_WEEK);
String[] str = {"","SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY" ,"SATURDAY"};
System.out.println(str[i]);


运行结果:

2016 7 1 

FRIDAY


说明:

Calendar的getActualMinimum
(int field)他传入的是一个int类型,这个方法的具体意思就是说根据你传入的参数代表的意思(年、月、周等)查询当前(年、月、周)拥有的最小值。

另外:

Calendar的getActualMaximum(int field)他传入的是一个int类型,这个方法的具体意思就是说根据你传入的参数代表的意思(年、月、周等)查询当前(年、月、周)拥有的最大值。

Shikyoh
2016-07-19 · TA获得超过396个赞
知道小有建树答主
回答量:220
采纳率:100%
帮助的人:125万
展开全部
你这两张图 一样啊.......
追问
哦哦哦错了错了,现在换
追答
代码粘的不太全啊 私信我 我帮你看看
.....不发私信是吧?行吧 我硬推
上段代码中的两行输出和下段代码的一行输出 跟输出英文月份 完全没有关系
仅仅是输出一个数值
而上段代码有效的原因很可能是因为在第47行修改了firstDay的值 并且输出英文月份是依赖这个值的
下段代码没有对firstDay做任何操作 所以 无效
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式