วันอังคารที่ 14 ตุลาคม พ.ศ. 2557

count words 01-10[2]


void setup(){


  String s = "Welcome to Thailand";

  int count = count_words(s);

  println(count);
}

int count_words(String s){
  int count = 1;


    for(int i=0;i<s.length();i++){

      if(s.charAt(i) ==' '){
        count=count+1;

     }
  }
  return count;
}

lab3 con[1]



void setup () {
  int []K = {
    4, 8, 5
  }; //your array
  int []R = {
    0, 1, 2
  }; //array of index
  int n = 4;//number you want to know
  int a = 0;
  for (int i = 0; i<K.length; i++) {
    if (n==K[i]) {
      println(K[i]+" has index = " +R[i]+" in K") ;
      a=a+K.length;//N
    } else if (n!=K[i])
      a=a-1;
  }
  if (a<=-1) {
    println(n+" is not in K");
  }
}