+ (additive operator)
- (subtraction operator)
* (multiplication operator)
/ (division operator)
mod (remainder operator)
var result = 1 + 2; // result is now 3
println(result);
result = result - 1; // result is now 2
println(result);
result = result * 2; // result is now 4
println(result);
result = result / 2; // result is now 2
println(result);
result = result + 8; // result is now 10
println(result);
result = result mod 7; // result is now 3
println(result);
var result = 0;
result += 1;
println(result); // result is now 1
result -= 1;
println(result); // result is now 0
result = 2;
result *= 5; // result is now 10
println(result);
result /= 2; // result is now 5
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)
var result = 1; // result is now 1
result--; // result is now 0
println(result);
result++; // result is now 1
println(result);
result = -result; // result is now -1
println(result);
var success = false;
println(success); // false
prinln(not success); // true
var result = 3;
result++;
println(result); // result is now 4
++result;
println(result); // result is now 5
println(++result); // result is now 6
println(result++); // this still prints prints 6!
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
def num1 = 1;
def num2 = 2;
println(num1 == num2); // prints false
println(num1 != num2); // prints true
println(num1 > num2); // prints false
println(num1 >= num2); // prints false
println(num1 < num2); // prints true
println(num1 <= num2); // prints true
Conditional Operators
and
or
0110
def username = "foo";
def password = "bar";
if ((username == "foo") and (password == "bar")) {
println("Test 1: username AND password are correct");
}
if ((username == "") and (password == "bar")) {
println("Test 2: username AND password is correct");
}
if ((username == "foo") or (password == "bar")) {
println("Test 3: username OR password is correct");
}
if ((username == "") or (password == "bar")) {
println("Test 4: username OR password is correct");
}
// Test 1: username AND password are correct
// Test 3: username OR password is correct
// Test 4: username OR password is correct
Type Comparison Operator
def str1="Hello";
println(str1 instanceof String); // prints true
def num = 1031;
println(num instanceof java.lang.Integer); // prints true
0 件のコメント:
コメントを投稿