วันอาทิตย์ที่ 31 สิงหาคม พ.ศ. 2557

Exercises Textbooks In Function.

Assume that two students take a java exam, and the result are assigned to two variables:

int mark1 = 44;
int mark2 = 51;



write a program which calculates and display the average mark as a float value. Check your answer with a calculator.

void setup () {
  size (120, 50);
  background (102, 51, 0);
  calculate (44, 51);
}

void calculate (int mark1, int mark2) {
  float sum = mark1+mark2;
  float average =sum/2;
  text ("Average = "+average, 20, 30);
}







ที่มา : Java for Students Second Edition, DOUGLAS BELL AND MIKE PARR, ISBN 0-13010922-3


Convert 37 Celsius to Fahrenheit

void setup () {
  size (150, 50);
  background (53, 204, 0);
  Convert (37) ;
}

void Convert (float Celsius) {
  float Fahrenheit = ((Celsius*9)/5)+32;
  text ("Fahrenheit = "+Fahrenheit, 20, 30);
}



ที่มา : Java for Students Second Edition, DOUGLAS BELL AND MIKE PARR, ISBN 0-13010922-3


Convert 3 feet into meters

void setup () {
  size (100, 50);
  background (153, 51, 102);
  calculate (3);
}

void calculate (float feet) {
  float meters = feet*0.3048;
  text ("Meters = "+round(meters), 20, 30);
}

ที่มา : Java for Students Second Edition, DOUGLAS BELL AND MIKE PARR, ISBN 0-13010922-3


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

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