วันศุกร์ที่ 31 สิงหาคม พ.ศ. 2550

week6

เป็นการใช้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

week7

เป็นการเรียนเกี่ยวกับarrey
จะเป็นการใช้คำสั่งarreyในการสั่งคำสั่งต่างๆ สมมุติว่าถ้ายังไม่ถึงตัวที่จะใช้งาน คำสั่งนั้นก็จะrunไปเรื่อย แต่พอถึงคำสั่งที่ต้องใช้ทำงานแล้ว คำสั่งจะจบทันที
public class week71 {
public static void main (String[]args){
int i , x[] , y[] , z[] ; String n[] ;
x = new int[3] ;
x[0] = 50 ;
x[1] = 79 ;
x[2] = 78 ;
y = new int[3] ;
y[0] = 80 ;
y[1] = 65 ;
y[2] = 79 ;
z = new int[3] ;
z[0] = 50 ;
z[1] = 65 ;
z[2] = 80 ;
n = new String[3] ;
n[0] = "GaMsT" ;
n[1] = "RoBbEn" ;
n[2] = "LaMpArD" ;
for(i = 0 ; i < 3 ; i++){
System.out.println("Full name is "+ n[i] +". First test score is "+ x[i] +" points. Second test score is "+ y[i] + " points. Third test score is " + z[i] +" points.");
System.out.println("The average score of "+ n[i] +" is "+ ((x[i] + y[i] + z[i])/3) +" points.");
if(x[i]<=y[i]) if(x[i]<=z[i])
System.out.println("lowest score "+ n[i] +" is "+ x[i] +" points."); else if(y[i]<=x[i]) if(y[i]<=z[i])
System.out.println("lowest score "+ n[i] +" is "+ y[i] +" points."); else if(z[i]<=x[i]) if(z[i]<=y[i])
System.out.println("lowest score "+ n[i] +" is "+ z[i] +" points."); if(x[i]>=y[i]) if(x[i]>=z[i])
System.out.println("highest score "+ n[i] +" is "+ x[i] +" points."); else if(y[i]>=x[i]) if(y[i]>=z[i])
System.out.println("highest score "+ n[i] +" is "+ y[i] +" points."); else if(z[i]>x[i]) if(z[i]>y[i])
System.out.println("highest score "+ n[i] +" is "+ z[i] +" points.");
System.out.println(); } } }
ตัวอย่างผลงาน
http://www.megaupload.com/?d=Q11M1ZVW