2008年12月12日金曜日

JavaFX Operator 演算子

演算子
+ (additive operator)
- (subtraction operator)
* (multiplication operator)
/ (division operator)
mod (remainder operator)
  1. var result = 1 + 2// result is now 3  
  2. println(result);  
  3.   
  4. result = result - 1// result is now 2  
  5. println(result);  
  6.   
  7. result = result * 2// result is now 4  
  8. println(result);  
  9.   
  10. result = result / 2// result is now 2  
  11. println(result);  
  12.   
  13. result = result + 8// result is now 10  
  14. println(result);  
  15.   
  16. result = result mod 7// result is now 3  
  17. println(result);  
  18.   
  19. var result = 0;  
  20. result += 1;  
  21. println(result); // result is now 1  
  22.   
  23. result -= 1;  
  24. println(result); // result is now 0  
  25.   
  26. result = 2;  
  27. result *= 5// result is now 10  
  28. println(result);  
  29.   
  30. result /= 2// result is now 5  
  31. println(result);  

- (Unary minus operator; negates a number)
++ (Increment operator; increments a value by 1)
-- (Decrement operator; decrements a value by 1)
not (Logical complement operator; inverts the value of a boolean)
  1. var result = 1// result is now 1  
  2.   
  3. result--;  // result is now 0  
  4. println(result);  
  5.   
  6. result++; // result is now 1  
  7. println(result);  
  8.   
  9. result = -result; // result is now -1  
  10. println(result);  
  11.   
  12. var success = false;  
  13. println(success); // false  
  14. prinln(not success); // true  
  15.   
  16. var result = 3;  
  17. result++;  
  18. println(result); // result is now 4  
  19. ++result;  
  20. println(result); // result is now 5  
  21. println(++result); // result is now 6  
  22. println(result++); // this still prints prints 6!  
  23. println(result); // but the result is now 7  

Equality and Relational Operators

== equal to
!= not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
  1. def num1 = 1;  
  2. def num2 = 2;  
  3.   
  4. println(num1 == num2); // prints false  
  5. println(num1 != num2); // prints true  
  6. println(num1 > num2);  // prints false  
  7. println(num1 >= num2); // prints false  
  8. println(num1 < num2);  // prints true  
  9. println(num1 <= num2); // prints true  

Conditional Operators

and
or
  1. 0110  
  2. def username = "foo";  
  3. def password = "bar";  
  4.   
  5. if ((username == "foo") and (password == "bar")) {  
  6.      println("Test 1: username AND password are correct");  
  7. }  
  8.   
  9. if ((username == "") and (password == "bar")) {  
  10.      println("Test 2: username AND password is correct");  
  11. }  
  12.   
  13. if ((username == "foo") or (password == "bar")) {  
  14.      println("Test 3: username OR password is correct");  
  15. }  
  16.   
  17. if ((username == "") or (password == "bar")) {  
  18.      println("Test 4: username OR password is correct");  
  19. }  
  20.   
  21. // Test 1: username AND password are correct  
  22. // Test 3: username OR password is correct  
  23. // Test 4: username OR password is correct  

Type Comparison Operator
  1. def str1="Hello";  
  2. println(str1 instanceof String);  // prints true  
  3.   
  4. def num = 1031;  
  5. println(num instanceof java.lang.Integer); // prints true  

0 件のコメント:

コメントを投稿