เป็นการใช้else if ในการสั่งคำสั่งต่างๆเพื่อที่จะใช้ได้หลายๆคำสั่งแต่ถ้าใช้if else ธรรมดาจะสามารถใช้ได้เพียงแค่2คำสั่ง
x = 150;
if(x==120){
System.out.println("x="+x); System.out.println("condition=true");}
else if(x>120 ){ System.out.println("fail"); System.out.println("it's to large");}
else if(x<120 ){ System.out.println("fail"); System.out.println("it's to low");};
เป็นการใช้คำสั่งelse if ในการดูว่าข้อมูลที่อยู่นั้นมากกว่าหรือน้อยกว่าหรือเท่ากับตค่าที่ตั้งไว้
ส่วนอีกคำสั่งนั้นคือcaseเกี่ยวกับการแยกเงื่อนไขให้ง่ายกว่าการใช้ if else
public class week62 {
public static void main (String args [])
{ int x; x = 100;
switch(x/10)
{
case 0:;
case 1:;
case 2:;
case 3:;
case 4:System.out.println("You're buffullo");break;
case 5:System.out.println("You're normal-.");break;
case 6:System.out.println("You're normal");break;
case 7:System.out.println("You're normal+.");break;
case 8:;
case 9:;
case 10:System.out.println("You're smart. oh! very good");break;
}
}
เกี่ยวกับการแยกข้อมูลถ้าได้สกอร์เท่านี้จะเป็นอย่างไร
ตัวอย่างผลงาน
http://www.megaupload.com/?d=KODIUEK0
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
ไม่มีความคิดเห็น:
แสดงความคิดเห็น