Java-basic-operators
提供:Dev Guides
Java-基本的な演算子
Javaは、変数を操作するための豊富な演算子セットを提供します。 私たちはすべてのJava演算子を次のグループに分けることができます-
- 算術演算子
- 関係演算子
- ビット演算子
- 論理演算子
- 割り当て演算子
- その他の演算子
算術演算子
算術演算子は、代数で使用されるのと同じ方法で数式で使用されます。 次の表は、算術演算子を示しています-
整数変数Aが10を保持し、変数Bが20を保持すると仮定します-
リンク:/java/java_arithmatic_operators_examples [例を表示]
Operator | Description | Example |
---|---|---|
PLUS (Addition) | Adds values on either side of the operator. | A PLUS B will give 30 |
- (Subtraction) | Subtracts right-hand operand from left-hand operand. | A - B will give -10 |
AST (Multiplication) | Multiplies values on either side of the operator. | A AST B will give 200 |
/(Division) | Divides left-hand operand by right-hand operand. | B/A will give 2 |
% (Modulus) | Divides left-hand operand by right-hand operand and returns remainder. | B % A will give 0 |
PLUSPLUS (Increment) | Increases the value of operand by 1. | BPLUSPLUS gives 21 |
— (Decrement) | Decreases the value of operand by 1. | B-- gives 19 |
関係演算子
Java言語でサポートされている関係演算子は次のとおりです。
変数Aが10を保持し、変数Bが20を保持すると仮定します-
リンク:/java/java_relational_operators_examples [例を表示]
Operator | Description | Example |
---|---|---|
== (equal to) | Checks if the values of two operands are equal or not, if yes then condition becomes true. | (A == B) is not true. |
!= (not equal to) | Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. | (A != B) is true. |
> (greater than) | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (A > B) is not true. |
< (less than) | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (A < B) is true. |
>= (greater than or equal to) | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (A >= B) is not true. |
⇐ (less than or equal to) | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (A ⇐ B) is true. |
ビット演算子
Javaでは、整数型、long、int、short、char、およびbyteに適用できるいくつかのビット演算子を定義しています。
ビット演算子はビットに対して機能し、ビットごとの操作を実行します。 a = 60およびb = 13であると仮定します。今バイナリ形式では、次のようになります-
a = 0011 1100
b = 0000 1101