Arithmetic operators:
Plus (+), minus (-), multiply (*), divide (/), withdraw (%)
Integer division directly cuts down decimals, not rounding
Public class mathtest{ publicstaticvoid main (string[] args) { int i = 3; int j = 2; int Math = I/ j; System.out.println (Math);} }
Value for output math: 1
int i = 3;int j = 2; System.out.println (i/j);
Same as the previous program with output 1.
Public class mathtest{ publicstaticvoid main (string[] args) { int i = 3; int j = 2; Double Math = I/ j; System.out.println (Math);} }
The value of the output math is: 1.0.
Public class mathtest{ publicstaticvoid main (string[] args) { double i = 3; // Double j = 2; same as output from next line int j = 2; Double Math = I/ j; System.out.println (Math);} }
The value of the output math is: 1.5.
To increment or decrement automatically:
Public class mathtest1{ publicstaticvoid main (string[] args) { int a = 7; int i = a++ + 3 ; System.out.println ("a =" + a); System.out.println ("i =" + i);} }
Output: a = 8 i = 10
Public class mathtest1{ publicstaticvoid main (string[] args) { int a = 7; int i = ++a + 3 ; System.out.println ("a =" + a); System.out.println ("i =" + i);} }
Output: a = 8 i = 11
Summary: int i = a++ + 3 is run first i = a + 3 and then run a = a + 1;
int i = ++a + 3 is run first A = a + 1 and then run i = a + 3;
If more complex operations need to be done, complex mathematical operations can be accomplished using the Java.lang.Math class's tool approach.
(Descending with sliding scale)
Relational operators
The relational operator generates a Boolean result. They evaluate the relationship between the operands ' values. If the relationship is true, the relational expression generates true (True), and False (false) if the relationship is not true. Relational operators include less than, greater than (>), less than or equal to (<=), greater than or equal to (>=), equals (= =), and not equal to (! =). equals and does not equal all built-in data types, but other comparisons do not apply to Boolean types.
Logical operators:
logical operators and (&&), or (| |) and NOT (! ) can generate a (true or false)-based on the logical relationship of the arguments.
If you expect to
The process control of my Java path