Groovy-logical-operators
提供:Dev Guides
Groovy-論理演算子
論理演算子は、ブール式を評価するために使用されます。 以下はGroovyで利用可能な論理演算子です-
Operator | Description | Example |
---|---|---|
&& | This is the logical “and” operator | true && true will give true |
This is the logical “or” operator | true | |
true will give true | ! | This is the logical “not” operator |
次のコードスニペットは、さまざまな演算子の使用方法を示しています。
class Example {
static void main(String[] args) {
boolean x = true;
boolean y = false;
boolean z = true;
println(x&&y);
println(x&&z);
println(x||z);
println(x||y);
println(!x);
}
}
上記のプログラムを実行すると、次の結果が得られます。 上記のように、結果は演算子の説明から予想されるとおりであることがわかります。
false
true
true
true
false