대학교/2.객체지향프로그래밍_JAVA

현재 시간에 따라 출력

Jcoder 2017. 4. 21. 22:30

<소스>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.*;
 
public class Welcome
{
    public static void main(String[] args) 
    {
        Date date = new Date();
        int currentHour = date.getHours();
        
        System.out.println("현재 시간은  " + date);
        
        switch (currentHour)
        {
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        {
            System.out.println("Good mornig");
            break;
        }
        case 11:
        case 12:
        case 13:
        case 14:
        {
            System.out.println("Good afternoon");
            break;
        }
        case 15:
        case 16:
        case 17:
        case 18:
        case 19:
        {
            System.out.println("Good evening");
            break;
        }
        default:
        {
            System.out.println("Good night");
            break;
        }
        }
    }
}
cs

< 실행 결과 >


Welcome.java