星期和月份

 1 package com.ibeve.demo;
 2 
 3 public class IfTest {
 4     public static void main(String[] args) {
 5         // 需求1:根据用户定义的数值不同,打印对应的星期英文
 6         int num = 1;
 7 
 8         if (num == 1)
 9             System.out.println("monday");
10         else if (num == 2)
11             System.out.println("monday");
12         else if (num == 3)
13             System.out.println("monday");
14         else if (num == 4)
15             System.out.println("monday");
16         else if (num == 5)
17             System.out.println("monday");
18         else if (num == 6)
19             System.out.println("monday");
20         else if (num == 7)
21             System.out.println("monday");
22         else
23             System.out.println("nonono");
24 
25         // 需求2:根据用户指定的月份,打印该月份所属的季节
26         // 3,4,5 春季 6,7,8 夏季 9,10,11 秋季 12,1,2 冬季
27 
28         int x = 3;
29 
30         if (x == 3 || x == 4 || x == 5)
31             System.out.println(x + "春季");
32         else if (x == 6 || x == 7 || x == 8)
33             System.out.println(x + "夏季");
34         else if (x == 9 || x == 10 || x == 11)
35             System.out.println(x + "秋季");
36         else if (x == 12 || x == 1 || x == 2)
37             System.out.println(x + "冬季");
38         else
39             System.out.println(x + "月份不存在");
40 
41         if (x > 12 || x < 1)
42             System.out.println(x + "月份不存在");
43         else if (x >= 3 && x <= 5)
44             System.out.println(x + "春季");
45         else if (x >= 6 && x <= 8)
46             System.out.println(x + "夏季");
47         else if (x >= 9 && x <= 11)
48             System.out.println(x + "秋季");
49         else
50             System.out.println(x + "冬季");
51 
52     }
53 }

 

posted @ 2018-04-26 15:15  IBEVE  阅读(381)  评论(0编辑  收藏  举报