แสดงบทความที่มีป้ายกำกับ lab7.1 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ lab7.1 แสดงบทความทั้งหมด

วันเสาร์ที่ 21 กันยายน พ.ศ. 2556

Fraction

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


Reversestring


void setup(){
String Vocab = "VOCABULARY"; //ใช้สตริงในการประกาศและกำหนดตัวอักษร print(Vocab+" reverse is "+reverseString(Vocab));//statement ให้ทำการแสดงผล } String reverseString(String A){ String R = "";//ประกาศสตริงเพื่อเก็บตัวอักษรใหม่ int i=0;//ประการและกำหนดเพื่อใช้ในการวนลูป while(i<A.length()){//เงื่อนไข while loop จะกระทำซ้ำๆตามเงื่อนไขมีการวนจนกว่าจะไม่เป็นไปตามเงื่อนไข จากนั้นก็จะจบการทำงานภายใน while loop char n=A.charAt(A.length()-1-i); R=R+n;//เก็บค่าตัวอักษรไว้ที่สตริง R i=i+1;//บวกเพิ่มเพื่อกลับไปวนลูป }//เมื่อไม่เป็นไปตามเงื่อนไขด้านบนก็จะจบการทำงานและมีการรีเทิร์นค่าของ R return R;//รีเทิร์นค่า R เพื่อนำไปใช้ }






การแสดงผล : VOCABULARY reverse is YRALUBACOV