java 今天是星期几_JAVA-今天是星期几

1496877-20190831214640470-521106024.jpg

1 import java.util.Scanner;

2

3 public class course01 {

4 public static void main(String[] args){

5 System.out.println("Welcome to 'What day is today'");

6

7 Scanner in = new Scanner(System.in);

8

9 System.out.println("Enter year: (e.g, 2012)");

10 int year = in.nextInt();

11

12 System.out.println("Enter month: 1 - 12 : ");

13 int month = in.nextInt();

14

15 System.out.println("Enter the day of the month: 1 - 31 :");

16 int day = in.nextInt();

17

18 // System.out.println(year+ month+day);

19

20 int temp = month;

21 if(temp == 1){

22 month = 13;

23 year -= 1;

24 }

25 else if(temp == 2){

26 month = 14;

27 year -= 1;

28 }

29

30 int k = year % 100;

31 int j = year / 100;

32

33 int h = (day + 26 * (month + 1) / 10 + k + k / 4 + j / 4 + 5 * j) % 7;

34

35 // System.out.println(h);

36

37 switch (h){

38 case 0 :System.out.println("Day of the week is Saturday"); break;

39 case 1 :System.out.println("Day of the week is Sunday"); break;

40 case 2 :System.out.println("Day of the week is Monday"); break;

41 case 3 :System.out.println("Day of the week is Tuesday"); break;

42 case 4 :System.out.println("Day of the week is Wednesday"); break;

43 case 5 :System.out.println("Day of the week is Thursday"); break;

44 case 6 :System.out.println("Day of the week is Friday"); break;

45 }

46 }

47 }

6d134dceb9ef118ed217a1c49573eb1d.png

标签:星期,JAVA,int,System,month,今天,year,println,out

来源: https://www.cnblogs.com/yingni/p/11440646.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值