---
# System prepended metadata

title: '003public class Switch-case結構式 {'

---


# 003public class Switch-case結構式 {
switch (n) {case 1:敘述1;break;
            case 2:敘述2;break;
            default:敘述4;}

亂數月份/當月天數判斷


```
public static void main(String[] args) {
		int Month = (int)(Math.random()*12 + 1); // 1 - 12
		System.out.println(Month);
		switch (Month){
			case 1: case 3: case 5: case 7: case 8: case 10: case 12:
				System.out.println("31");
				break;
			case 4: case 6: case 9: case 11:
				System.out.println("30");
				break;
			case 2:
				System.out.println("28");
				break;
			default:(其他)
				System.out.println("OK");
		}
	}

}
```
