JAVA Tutorial (6 Part Series)
1 1. Hello World in JAVA
2 2. Variables, Datatypes, Operators in JAVA
… 2 more parts…
3 3. String in JAVA
4 4. Operators, Operands, Expression, Operator Precedence
5 5. If-then block in JAVA
6 6. Expressions, Statements, if-then-else , Methods, Method Overloading
Example of operators
int result = 1 + 2; // addition
result = result - 1; // subtraction
result = result * 10; // multiplication
result = result / 5; // division
result = result % 3; // modulus
Enter fullscreen mode Exit fullscreen mode
Abbreviating of operators
// result = result + 1;
result++;
// result = result - 1;
result--;
// result = result + 2;
result += 2;
// result = result * 10;
result *= 10;
// result = result / 3;
result /= 3;
// result = result % 2;
result %= 2;
Enter fullscreen mode Exit fullscreen mode
Arithmetic operators
+, -, *, /, %, ++, —
Assignment operators
=, +=, -=, *=, /=, %=, &=, |=, ^=, >>=, <<=
Comparison operators
==, !=, >, <, >=, <=
Logical operators
&&, ||, !
Bitwise operators
&, |, ~, ^, <<, >>, >>>
Another operator is Ternary Operator
boolean loggedIn = false;
String userStatus = loggedIn ? "User is loggedIn" : "User is not logged in";
System.out.println(userStatus);
Enter fullscreen mode Exit fullscreen mode
More details can be found in
w3schools.com
oracle.com
Java Operator Precedence
JAVA Tutorial (6 Part Series)
1 1. Hello World in JAVA
2 2. Variables, Datatypes, Operators in JAVA
… 2 more parts…
3 3. String in JAVA
4 4. Operators, Operands, Expression, Operator Precedence
5 5. If-then block in JAVA
6 6. Expressions, Statements, if-then-else , Methods, Method Overloading
原文链接:4. Operators, Operands, Expression, Operator Precedence
暂无评论内容