Arithmetic, Logic, and Assignment Operators JAVA

Arithmetic, Logic, and Assignment Operators JAVA

Arithmetic operators

Listed below are the operators used in arithmetic calculation process for coding Java:

Operator
Information
+
addition
-                   Subtraction (as a sign of minus)
*                   Multiplication
/                   Distribution
%
modulus
++
increment
-
decrement


Example Java program using arithmetic operators:
01class OperatorAritmatika {
02public static void main(String args[]) { int iresult, irem;
03double dresult, drem; iresult = 10 / 3;
04irem = 10 % 3;
05dresult = 10.0 / 3.0;
06drem = 10.0 % 3.0;
07System.out.println("(Integer) Hasil pembagian dan sisa bagi dari 10 / 3 = "
08+iresult);
09System.out.println("(Float) Hasil pembagian dan sisa bagi dari 10.0 / 3.0 = "
10+dresult);
11}
12}


Arithmetic, Logic, and Assignment Operators JAVA
coding result, in the example I use with the result of integer division operator and float



Logical operators

Relational operators refers to the relationship that one can have other values, whereas the logic refers to the way in which the true and false values ​​can be linked together. Due to the relational operators produce true / false value, usually often associated with logical operators.

Operator
Information
&
AND
|
OR
^
XOR (exclusive OR)
||
Short-circuit OR
&&
Short-circuit AND
!
NOT

sample java program using logical operators:
01class operatorLogika {
02public static void main(String args[]) { int i, j;
03boolean b1, b2;
04= 10;
05= 11;
06if(i < j)
07System.out.println("i < j"); if(i <= j)
08System.out.println("i <= j"); if(i != j)
09System.out.println("i != j"); if(i == j)
10System.out.println("this won't execute"); if(i >= j)
11System.out.println("this won't execute"); if(i > j)
12System.out.println("this won't execute");
13b1 = true; b2 = false; if(b1 & b2)
14System.out.println("this won't execute"); if(!(b1 & b2))
15System.out.println("!(b1 & b2) is true"); if(b1 | b2)
16System.out.println("b1 | b2 is true"); if(b1 ^ b2)
17System.out.println("b1 ^ b2 is true");
18}
19}

Arithmetic, Logic, and Assignment Operators JAVA
coding results, will display the results of logic as an example i <j (i smaller than j), in the order of i smaller than j.


Assignment operator

This operator is used to give a value to a variable or object. The symbol of this operator is "=", the form of syntax is as follows:
var = value;
No other format in the provision of value do not normally like the following example:
int x, y, z; x = y = z = 270;
other forms of shorthand assignment operator is as follows:

Operator
Example
Equation
+ =
x + = 4
x = x + 4
- =
x - = 4
x = x - 4
* =
x * = 4
x = x * 4
/ =
x / = 4
x = x / 4
% =
x% = 4
x = x% 4

Berlangganan update artikel terbaru via email:

0 Response to "Arithmetic, Logic, and Assignment Operators JAVA"

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel