class Fraction {
int n;
int d;
Fraction(int a, int b) {
n=a;
d=b;
}
void add(int z) {
this.n=this.d*z+this.n;
}
void minus(int z) {
this.n=this.n-z*this.d;
}
void mul(int s) {
this.n=this.n*s;
}
String toString() {
String s =this.n+"/"+this.d;
return s;
}
void reciprocal() {
int temp;
temp=n;
n=d;
d=temp;
}
}
void setup() {
background(0);
Fraction f =new Fraction(9, 5);
Fraction g =new Fraction(9, 8);
g.add(5);
f.minus(8);
f.mul(3);
textSize(10);
text(f.toString(),10,40);
text(g.toString(),10,70);
text(g.toString(),10,70);
}
สามารถรันโค้ดได้ที่ : http://processingjs.org/tools/processing-helper.html
ไม่มีความคิดเห็น:
แสดงความคิดเห็น