# 17號筆記 ###### tags: `筆記本` # 1.Switch 月份用法 ``` public class SwitchDemo { public static void SumMonthDaysBySwitch(int month) { switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: System.out.println("31 days"); break; case 2: System.out.println("28 days"); break; case 4: case 6: case 9: case 11: System.out.println("30 days"); break; default: System.out.println("Invalid month");//無效月份 break; } } public static void SumMonthDaysByIf(int month) { if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { System.out.println("31 days"); }else if (month == 2) { System.out.println("28 days"); }else if (month == 4 || month == 6 || month == 9 || month == 11 ) { System.out.println("30 days"); }else { System.out.println("Invalid month"); } } public static void main(String[] args) { SumMonthDaysByIf(2); SumMonthDaysBySwitch(2); } } ``` ``` public class SwitchDemo2 { public static void SumMonthDaysBySwitch2(int month) { switch (month) { case 1: System.out.println("--1"); case 3: System.out.println("--3"); case 5: System.out.println("--5"); case 7: System.out.println("--7"); case 8: System.out.println("--8"); case 10: System.out.println("--10"); case 12: System.out.println("31 days"); break; case 2: System.out.println("28 days"); break; case 4: System.out.println("--4"); case 6: System.out.println("--6"); case 9: System.out.println("--9"); case 11: System.out.println("30 days"); break; default: System.out.println("Invalid month"); break; } } public static void main(String[] args) { SumMonthDaysBySwitch2(3); SumMonthDaysBySwitch2(2); SumMonthDaysBySwitch2(4); SumMonthDaysBySwitch2(13); } } ``` # 2. ``` public class Test50716 { public static void main(String[] args) { StringBuilder msg = new StringBuilder("Hello jim!!"); int loc = 0; try { for (loc=0 ; loc<12 ; loc++) { switch (msg.charAt(loc)) { case 'i': case 'e': case 'o': String ucs = Character.toString(msg.charAt(loc)).toUpperCase(); msg.replace(loc, loc+1, ucs); } } }catch (Exception e) { System.out.println("Out of Limits"); } System.out.println(msg); } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up