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

Palindrome



String word="RADAR";
void setup() {
  size (200, 50);
  background (204, 53, 53);
  palindrome (isPalindrome (word, reversString()));
}
String reversString () {
  char [] a = new char[word.length()];
  int i =0;
  int j =word.length()-1;
  while (i<word.length ()) {
    a[i] = word.charAt(j);
    i++;
    j--;
  }
  String b = new String(a);
  return b;
}
boolean isPalindrome (String word, String a) {
  String c = word.toUpperCase();
  String cNew = a.toUpperCase();
  boolean d = c.equals(cNew);
  return d;
}
void palindrome (boolean e) {
  if (e==true) {
    text (word+" is palindrome", 50, 30);
  }
  else {
    text (word+" isn't palindrome", 20, 20);
  }
}

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

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