Groovy-arithmetic-operators
提供:Dev Guides
Groovy-算術演算子
Groovy言語は、すべての言語として通常の算術演算子をサポートしています。 以下はGroovyで利用可能な算術演算子です-
Operator | Description | Example |
---|---|---|
PLUS | Addition of two operands | 1 PLUS 2 will give 3 |
− | Subtracts second operand from the first | 2 − 1 will give 1 |
* | Multiplication of both operands | 2* 2 will give 4 |
/ | Division of numerator by denominator | 3/2 will give 1.5 |
% | Modulus Operator and remainder of after an integer/float division | 3 % 2 will give 1 |
PLUSPLUS | Incremental operators used to increment the value of an operand by 1 |
int x = 5;
|
— | Incremental operators used to decrement the value of an operand by 1 |
int x = 5; x--; xは4を与える |
次のコードスニペットは、さまざまな演算子の使用方法を示しています。
上記のプログラムを実行すると、次の結果が得られます。 上記のように、結果は演算子の説明から予想されるとおりであることがわかります。