4. เลือกปฏิบัติ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 4-7  ตัวอย่างการเขียนคำสั่ง if ให้สั้น ในกรณีที่มีเพียงคำสั่งเดียวหลังเงื่อนไข if
    if (w < 0) w = w + 7;
    if (w == 0) System.out.println("วันเสาร์");
    if (w == 1) System.out.println("วันอาทิตย์");
    if (w == 2) System.out.println("วันจันทร์");
    if (w == 3) System.out.println("วันอังคาร");
    if (w == 4) System.out.println("วันพุธ");
    if (w == 5) System.out.println("วันพฤหัสบดี");
    if (w == 6) System.out.println("วันศุกร์");
©2009 S.Prasitjutrakul