เป็นการเรียนเกี่ยวกับ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
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
ไม่มีความคิดเห็น:
แสดงความคิดเห็น