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 |
๋ฐ์ํ
'๐ป ํ๋ก๊ทธ๋๋ฐ > JAVA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
2-11 ์กฐ๊ฑด ๋ฐ๋ณต๋ฌธ if II (0) | 2016.06.26 |
---|---|
2-9 ์กฐ๊ฑด ํ๋จ๋ฌธ switch II (0) | 2016.06.26 |
2-7 ์กฐ๊ฑดํ๋จ๋ฌธ if (0) | 2016.06.26 |
2-6 ํฐ ์ ์ Big Decimal (0) | 2016.06.26 |
2-5 ํ๋ก๊ทธ๋จ๋์ค ํค๋ณด๋ ์ ๋ ฅ๊ฐ ๋ฐ๊ธฐ (0) | 2016.06.26 |