๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ป ํ”„๋กœ๊ทธ๋ž˜๋ฐ/JAVA

2-8 ์กฐ๊ฑด ํŒ๋‹จ๋ฌธ switch


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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package pack;
 
import java.util.Scanner;
 
public class Test8switch {
 
    public static void main(String[] args) {
        // ์กฐ๊ฑด ํŒ๋‹จ๋ฌธ Switch๋ฌธ
        int nai =42;
        nai = nai / 10 * 10;
        //System.out.println(nai);
        switch (nai) {
        case 30//์ค‘๊ด„ํ˜ธ ๋ธ”๋Ÿญ์„ ๋‘๋ฅด์ง€ ์•Š๋Š”๋‹ค
            System.out.println("์‚ผ์‹ญ๋Œ€");
            System.out.println("์ธ์ƒ์˜ ๋ฐ”์œ ๋‚  ๋งŽ์Œ");
            break;
        case 40:
            System.out.println("์‚ฌ์‹ญ๋Œ€ ์ค‘๋…„");
            System.out.println("์ธ์ƒ์˜ ๋ฐ˜์ด ์ง€๋‚ฌ๋„ค์š”~");
            break;
        default:
            System.out.println("๊ธฐํƒ€");
            break;
 
        }
        System.out.println();
        //double time = Math.random();
        //int time = (int)(Math.random() * 10);
        int time = (int)(Math.random() * 4+ 8;
        //System.out.println(time);
        switch (time) {
        case 8:
            System.out.println("์ถœ๊ทผํ•˜์ž");
            break;
        case 9:
            System.out.println("ํšŒ์˜ํ•˜์ž");
            break;
        case 10:
            System.out.println("ํ”„๋กœ๊ทธ๋žจ ์งœ์ž");
            break;
        default:
            System.out.println("๋ช…์ƒํ•˜๊ธฐ");
        
        }
        System.out.println();
        System.out.println("์ž‘์—… ๊ณ„์†");
        //๋ฌธ์ œ : ํ‚ค๋ณด๋“œ๋กœ ๋ถ€ํ„ฐ ๋…„๊ณผ ์›”์„ ๊ฐ๊ฐ ์ž…๋ ฅ๋ฐ›์•„
        //        ํ•ด๋‹น๋…„ ์›”์˜ ๋‚  ์ˆ˜๋ฅผ ์ถœ๋ ฅ, ์œค๋…„์„ ์ฒดํฌ.
        //        ์œค๋…„์€ ํ•ด๋‹น๋…•์ด 4์˜ ๋ฐฐ์ˆ˜ ์ด๊ณ , 100์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹ˆ๊ฑฐ๋‚˜ 400์˜ ๋ฐฐ์ˆ˜
        //        ์ถœ๋ ฅ ****๋…„ **์›”์€ **์ผ ํ‰๋…„
        //Case๋ฌธ์„ ์“ฐ๊ณ , ๊ทธ ์•ˆ์— if๋ฌธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค (์œค๋…„์ฒดํฌ ํ• ๋•Œ).
        
        int year, month, day/*, yoon*/;
        Scanner sc = new Scanner(System.in);
        System.out.print("ํ•ด๋‹น๋…„๋„ ์ž…๋ ฅ:");
        year = sc.nextInt();
        System.out.print("ํ•ด๋‹น ์›” ์ž…๋ ฅ:");
        month = sc.nextInt();
        String yoon = "ํ‰๋…„";
        
        if((month <= 13) && (month > 0)){
        
            switch(month) {
            case 2:
                if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)){
                    day = 29;
                    yoon = /*1*/ "์œค๋…„";
                }else{
                    day = 28;
                    yoon = /*2*/ "ํ‰๋…„";
                }
                break;        
            case 4:    case 6:    case 9:    case 11:
                day = 30;
                break;
            default:
                day = 31;
                break;
            }
            yoon = (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))?"์œค๋…„":"ํ‰๋…„";
            System.out.println(year + "๋…„ " + month + "์›”์€ " + day + "์ผ ์ด์žˆ์œผ๋ฉฐ " + yoon + "์ž…๋‹ˆ๋‹ค.");
        
        
        //yoon = (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))?1:2;
        
        /*if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)){
            yoon = 1;
        }else{
            yoon = 2;
        }*/        
        
        /*switch (yoon) {
        case 1:
            System.out.println(year + "๋…„ " + month + "์›”์€ " + day + "์ผ ์žˆ๊ณ  " + "์œค๋…„ ์ž…๋‹ˆ๋‹ค.");
            break;
        default:
            System.out.println(year + "๋…„ " + month + "์›”์€ " + day + "์ผ ์žˆ๊ณ  " + "ํ‰๋…„ ์ž…๋‹ˆ๋‹ค.");
            break;
        }*/
        
                
        }else{
            System.out.println("๋‹ฌ๋ ฅ์˜ ์›”์€ 1์›” ~ 12์›” ๊นŒ์ง€๋งŒ ์„ค์ •์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.");
        }
 
    }
}
 
cs


๋ฐ˜์‘ํ˜•