WeGievU.Com
WeGievU.Com
WeGievU.Com
User :
Pass :
  WeGievU.Com
WeGievU.Com
WeGievU.Com
» E-Learning Room > Java
WeGievU.Com
คำสั่งควบคุม Switch 
( 290  Views )

Mon 01-09-2551 Time 12:30
Category: Java/ WeGievU.Com 0Comments
WeGievU.Com
รูปแบบ
switch (ตัวแปร)
{ case ค่าที่ 1 : คำสั่งที่ 1;
break;
case ค่าที่ 2 : คำสั่งที่ 2;
break;

case ค่าที่ N : คำสั่งที่ N;
break;
default : คำสั่งเมื่อไม่มีค่าที่ตรงกับค่าที่ระบุใน case; }
 
public class Testswitch
  { public static void main(String args [ ])
     {
     int year = 5;
     switch (year)
     { case 5 : System.out.println("5");
     break;
     case 15 : System.out.println("15");
     break;
     case 30 : System.out.println("30");
     break;
     default : System.out.println("Error"); }
     }
 }
ผลการ Run


public class Testswitch
  { public static void main(String args [ ])
     {
     int year = 6;
     switch (year)
     { case 5 : System.out.println("5");
     break;
     case 15 : System.out.println("15");
     break;
     case 30 : System.out.println("30");
     break;
     default : System.out.println("Error"); }
     }
 }
ผลการ Run



แสดงความคิดเห็น “ คำสั่งควบคุม Switch   Comment”
WeGievU.Com
WeGievU.Com


Learning
| Tip | Knowledge
Copyright (c) 2010 by Wegiveu.com Team ( We Give Everything )