วันพุธที่ 7 สิงหาคม พ.ศ. 2556

Function:Hard

Question...Write a method which returns the inch equivalent of its centimetre parameter.An example invocation is:
               เขียนฟังก์ชันที่มีการรีเทิร์นค่านิ้ว โดยกำหนด เซนติเมตรในฟังชั่นพารามิเตอร์
                float inches = inchEquivalent(2.5f);

               Multiply centimetres by 0.394 to calculate inches.
               หาเซนติเมตรโดย 0.394 ในการคำนวณนิ้ว

Answer...

void setup(){
  inchEquivalent(2.5);
  println("Equivalent "+inchEquivalent(2.5)+"inch");
}
float inchEquivalent(float x){
  float n;
  n = x*0.394;
  return n;
}



source : Java for students
Douglas Bell and Mike Parr. -- 2nd ed. page 61
ISBN : 0-13010922-3
การแสดงผล


ไม่มีความคิดเห็น:

แสดงความคิดเห็น