Operator Summery:
Larger number means higher precedence.
Operator Challenge:
public class OperatorChallange {
public static void main(String[] args) {
double var1 = 20.00d;
double var2 = 80.00d;
double result1 = (var1 + var2) * 100.00;
System.out.println("My value =" + result1);
double reminder = result1 % 40.00d;
System.out.println("Reminder = " + reminder);
boolean check = true;
boolean isNoReminde = (reminder == 0) ? true : false;
System.out.println("IsNiReminder + " +isNoReminde);
if (!isNoReminde) {
System.out.println("Resultant reminser is not zero !!");
}
}
}
Summary of Operators
The following quick reference summarizes the operators supported by the Java programming language.
Simple Assignment Operator
= Simple assignment operator
Arithmetic Operators
+ Additive operator (also used for String concatenation) - Subtraction operator * Multiplication operator / Division operator % Remainder operator
Unary Operators
+ Unary plus operator; indicates positive value (numbers are positive without this, however) - Unary minus operator; negates an expression ++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 ! Logical complement operator; inverts the value of a boolean
Equality and Relational Operators
== Equal to != Not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to
Conditional Operators
&& Conditional-AND
|| Conditional-OR
?: Ternary (shorthand for
if-then-else
statement)
Type Comparison Operator
instanceof Compares an object to a specified type
Bitwise and Bit Shift Operators
~ Unary bitwise complement << Signed left shift >> Signed right shift >>> Unsigned right shift & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR
Java Operator Precedence Table
Precedence | Operator | Type | Associativity |
---|---|---|---|
15 | () [] · |
Parentheses Array subscript Member selection |
Left to Right |
14 | ++ -- |
Unary post-increment Unary post-decrement |
Right to left |
13 | ++ -- + - ! ~ ( type ) |
Unary pre-increment Unary pre-decrement Unary plus Unary minus Unary logical negation Unary bitwise complement Unary type cast |
Right to left |
12 | * / % |
Multiplication Division Modulus |
Left to right |
11 | + - |
Addition Subtraction |
Left to right |
10 | << >> >>> |
Bitwise left shift Bitwise right shift with sign extension Bitwise right shift with zero extension |
Left to right |
9 | < <= > >= instanceof |
Relational less than Relational less than or equal Relational greater than Relational greater than or equal Type comparison (objects only) |
Left to right |
8 | == != |
Relational is equal to Relational is not equal to |
Left to right |
7 | & | Bitwise AND | Left to right |
6 | ^ | Bitwise exclusive OR | Left to right |
5 | | | Bitwise inclusive OR | Left to right |
4 | && | Logical AND |
Left to right |
3 | || | Logical OR | Left to right |
2 | ? : | Ternary conditional | Right to left |
1 | = += -= *= /= %= |
Assignment Addition assignment Subtraction assignment Multiplication assignment Division assignment Modulus assignment |
Right to left |
Larger number means higher precedence.
Operator Challenge:
public class OperatorChallange {
public static void main(String[] args) {
double var1 = 20.00d;
double var2 = 80.00d;
double result1 = (var1 + var2) * 100.00;
System.out.println("My value =" + result1);
double reminder = result1 % 40.00d;
System.out.println("Reminder = " + reminder);
boolean check = true;
boolean isNoReminde = (reminder == 0) ? true : false;
System.out.println("IsNiReminder + " +isNoReminde);
if (!isNoReminde) {
System.out.println("Resultant reminser is not zero !!");
}
}
}
No comments:
Post a Comment