asdtiang的博客 感谢blogjava提供的博客交流平台

 ```result = num1 + num2; days = ["Mon","Tue","Wed","Thu","Fri"];```

 ```+ （加运算符） - （减运算符） * （乘运算符） / （除运算符） mod （求余运算符）```

 ```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);```

 ```- 一元减运算符；对某个数字求反 ++ 递增运算符；按 1 递增某个值 -- 递减运算符；按 1 递减某个值 not 逻辑求补运算符；对布尔值求反```

 ```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 println(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 6! println(result); // but the result is now 7```

 ```== 等于 != 不等于 > 大于 >= 大于或等于 < 小于 <= 小于或等于```

 ```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```

 ```and or```

 ```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```

`instanceof` 运算符将对象与指定的类型相比较。您可以使用该运算符来确定某个对象是否为特定类的实例：

 ```def str1="Hello"; println(str1 instanceof String); // prints true def num = 1031; println(num instanceof integer); // prints true```

 只有注册用户登录后才能发表评论。 网站导航: 相关文章:

posts - 80, comments - 24, trackbacks - 0, articles - 32