
SelectionDemo.java
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 | public class SelectionDemo { public static void main(String[] args) { System.out.println(); if (3 < 5) { System.out.println( "3大於5發生了!" ); } else if (4 < 5) { System.out.println( "4大於5發生了!" ); } else if (5 < 5) { System.out.println( "5大於5發生了!" ); } else if (6 < 5) { System.out.println( "6當然大於5哩!" ); } else { System.out.println( "沒有符合的條件" ); } System.out.println(); } } /* 檔名: SelectionDemo.java 作者: Kaiching Chang 時間: September, 2014 */ |
SwitchDemo.java
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 | // 示範 switch-case 的類別 public class SwitchDemo { public static void main(String[] args) { System.out.println(); switch (6) { case 3: System.out.println( "選擇是3..." ); break ; case 4: System.out.println( "選擇是4..." ); break ; case 5: System.out.println( "選擇是5..." ); break ; case 6: System.out.println( "選擇是6..." ); break ; default : System.out.println( "沒有符合的" ); } System.out.println(); } } /* 檔名: SwitchDemo.java 作者: Kaiching Chang 時間: September, 2014 */ |
the end

沒有留言:
張貼留言